Git Branch Management Cheatsheet - Command Reference

Git branches are the core of team collaboration. All essential branch operation commands organized by Create & Switch, Merge & Rebase, Remote Branches, and Cleanup for managing multi-branch development workflows.

Version Control·19 commands·Last updated 2026-07-21
Back to Version Control

Create & Switch 5

git branch feature/login
Create a new branch
git checkout feature/login
Switch to a branch
git checkout -b feature/login
Create and switch to a new branch
git switch feature/login
Switch to a branch (new command)
git switch -c feature/login
Create and switch (new command)

Merge & Rebase 5

git merge feature/login
Merge branch into current branch
git merge --no-ff feature/login
Force create merge commit
git rebase main
Rebase onto main branch
git rebase -i HEAD~3
Interactive rebase of last 3 commits
git rebase --abort
Abort rebase

Remote Branches 5

git push origin feature/login
Push branch to remote
git push -u origin feature/login
Push and set upstream tracking
git fetch origin
Fetch remote updates
git pull origin feature/login
Pull remote branch
git branch -r
View remote branches

Delete & Cleanup 4

git branch -d feature/login
Delete merged branch
git branch -D feature/login
Force delete unmerged branch
git push origin --delete feature/login
Delete remote branch
git branch --merged
View merged branches

💡 Tips

  • Both git switch and git checkout can switch branches, but switch is more focused on branch operations.
  • rebase rewrites commit history — never rebase on shared branches that have been pushed.
  • --no-ff merge preserves branch history, suitable for merging feature branches into main.
  • git branch -vv shows tracking relationships between local and remote branches.

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it