Show Menu
Cheatography

Git Rebase Workflow Cheat Sheet by

Because I want you to ignore the complexity and rebase more. Graphical interface recommendations.Long form commands are utilized for clarity (and recommended).

Start Work

$ git fetch origin
$ git switch -c <branch name> origin­/main
$ git branch -D main master

Parallel Develo­pment

$ git fetch origin
Grab the latest from remote
$ git switch -c <br­anc­h> origin­/main
Create a branch off the mainline
$ git rebase origin­/main
Update branch to mainline
$ git worktree add <ne­wpa­th> origin­/main -b <ho­tpa­tch>
Create a new repo copy to develop a hotpatch

Move Work

$ git cherry­-pick <co­mmi­t>
$ git rebase <branch name>
$ git rebase <co­mmi­t>
Find <co­mmi­t> with $ gitk

Test Committed

$ git stash --incl­ude­-un­tracked
$ git stash pop

Collab­orate

$ git fetch origin
$ git rebase origin­/main
$ git push origin <br­anc­h>
Include --force on personal branch
$ git push origin --delete <br­­­a­n­c­­h>
Delete Remote Branch
 

Work in progress

$ git commit --fixup HEAD
 
$ git config --global alias.f­ixup 'commit --fixup'
$ git commit --fixup <co­mmi­t>
$ git commit --fixup :/<­mes­sag­e>
$ git rebase -i <co­mmi­t>~1
 
$ git config --global rebase.au­tos­quash true

Fix Work

Fix Commit Message
$ git rebase -i origin­/main
reword
Impo­rtant Commit First
$ git rebase -i origin­­­/main
Reorder lines
Combine Commits
$ git rebase -i origin­­­/main
fixup
$ git rebase -i origin­­­/main
squash
Break Apart Work
$ git rebase -i origin­­­/main
edit
$ git gui
Use the "­Unstage Lines" feature

The icon operates the whole file

Save Work

$ git add <fi­le>
$ git commit
$ git stash push -m <me­ssa­ge>
$ git stash apply stash^­/<m­ess­age>

Clean Up

$ git fetch origin --purge
$ git switch --detach origin­/main
$ git branch --merged
$ git branch --delete <br­anc­h1> < branch­2>
$ git push origin --delete <br­­an­c­h>
 

<co­mmi­t>

Hash
:/msg
Branch
<br­anc­h>:/msg
origin­/branch

Branch or Remote

origin­/main
<br­anc­h>
origin
<re­mot­e>
$ git push origin main
push <re­mot­e> <br­anc­h>
$ git fetch origin
fetch <re­mot­e>
$ git rebase origin­/main
rebase <br­anc­h>

Cancel That

$ git rebase --abort
$ git merge --abort
$ git cherry­-pick --abort
$ git reset --hard <co­mmi­t>
If the operation completed, find your starting point:
$ git reflog

Don't Do

$ git reset --hard
$ git clean --force
$ git switch <br­anc­h> --force
These types of commands will destroy data, not retrie­vable.

What Is?

Detached HEAD
 
There is no pointer to <co­mmi­t> other than HEAD
 

Comments

This is awesome, thanks!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Git Cheat Sheet
          Bash Dev Cheat Sheet