Git Merge & Rebase Cheat Sheet

Git merge vs rebase explained. When to use each, how to resolve conflicts, interactive rebasing, and cherry-picking.

Last Updated: May 1, 2025

Merge Commands

git merge branch
Merge specified branch into current branch
git merge --no-ff branch
Force a merge commit even if fast-forward possible
git merge --squash branch
Squash all commits into one before merging
git merge --abort
Abort a merge in progress if conflicts arise
git merge --continue
Continue merge after resolving conflicts
git merge -X theirs branch
Auto-resolve conflicts favoring merged branch
git merge -X ours branch
Auto-resolve conflicts favoring current branch
git mergetool
Launch visual merge tool for conflict resolution

Rebase Commands

git rebase branch
Reapply current branch commits on top of another
git rebase -i HEAD~3
Interactive rebase last 3 commits (squash/fixup/reword)
git rebase --onto newbase oldbase
Transplant branch to a new base commit
git rebase --continue
Continue rebase after resolving conflicts
git rebase --skip
Skip the current commit during rebase
git rebase --abort
Abort rebase and return to original state
git pull --rebase
Fetch and rebase instead of merge (cleaner history)
git config --global pull.rebase true
Always use rebase when pulling

Cherry-Pick & Advanced

git cherry-pick commit
Apply a specific commit to current branch
git cherry-pick --continue
Continue cherry-pick after resolving conflicts
git cherry-pick --abort
Abort cherry-pick operation
git reflog
Show log of ALL HEAD movements (recovery tool)
git bisect start
Begin binary search for a bug-introducing commit
git bisect good commit
Mark a commit as good during bisect
git bisect bad commit
Mark a commit as bad during bisect
git bisect reset
End bisect session and return to original HEAD
Pro Tip: Rebase for a clean linear history on feature branches. Merge when integrating completed work into shared branches.