Skip to main content

Branching & Merging Cheatsheet

Branches

CommandAction
git branchList local branches
git branch -aList all branches (+ remote)
git branch -vList with last commit info
git branch <name>Create a branch
git switch -c <name>Create and switch to branch
git switch <name>Switch to existing branch
git switch -Switch to previous branch
git branch -d <name>Delete merged branch
git branch -D <name>Force-delete branch
git branch -m <new>Rename current branch
git branch --mergedList merged branches
git branch --no-mergedList unmerged branches

Merging

CommandAction
git merge <branch>Merge branch into current
git merge --no-ff <branch>Force merge commit
git merge --squash <branch>Squash all commits into one
git merge --abortCancel an in-progress merge

Rebasing

CommandAction
git rebase <branch>Rebase current onto branch
git rebase -i HEAD~NInteractive rebase last N commits
git rebase -i --autosquashAuto-squash fixup commits
git rebase --continueContinue after resolving conflict
git rebase --abortCancel the rebase
git pull --rebasePull with rebase (no merge commit)

Conflict Resolution

CommandAction
git statusShow conflicted files
git checkout --ours <file>Keep your version
git checkout --theirs <file>Keep their version
git add <file>Mark conflict as resolved
git merge --abortCancel merge
git rebase --abortCancel rebase

Interactive Rebase Commands

KeyAction
pickKeep commit as-is
rewordChange commit message
editPause to modify commit
squashMerge into previous (keep message)
fixupMerge into previous (discard message)
dropDelete the commit