Skip to content

Searchable reference guide for essential and advanced Git commands with explanations and examples.

Loading tool

About Git Cheat Sheet

A searchable reference of about 80 Git commands with a short explanation of each, grouped into setup and config, basics, branching, merging and rebasing, remotes, stash, history, undo and reset, tags, and advanced commands like bisect, worktree and sparse-checkout. You can filter by topic, search by command or purpose, and copy any command.

Common uses

  • Look up the command to undo the last commit
  • Find the right flag for a log, diff or stash operation
  • Recover lost commits with reflog
  • Refresh less common commands like bisect, worktree or rebase --onto

FAQ

How do I undo the last commit but keep my changes?
Run 'git reset --soft HEAD~1' to keep the changes staged, or 'git reset HEAD~1' to keep them unstaged. If the commit is already pushed, 'git revert <commit>' is safer.
What is the difference between git merge and git rebase?
Merge joins two branches with a merge commit and keeps history as it happened. Rebase replays your commits on top of another branch to make history linear, which rewrites those commits.
What is the difference between git fetch and git pull?
git fetch downloads new commits from the remote without changing your branch. git pull fetches and then merges (or rebases) them into the current branch.
Is git push --force-with-lease safer than --force?
Yes. --force-with-lease refuses to overwrite the remote branch if someone else has pushed to it since you last fetched.