Git Cheatsheet
Free Git cheatsheet. Searchable reference for common Git commands โ branching, merging, undoing changes, remotes, and more.
Frequently asked questions
What is the difference between git fetch and git pull?
git fetch downloads commits and branches from a remote but leaves your current branch untouched โ it just updates your view of the remote. git pull does a fetch and then immediately merges (or rebases, if configured) the fetched changes into your current branch. fetch is the safer, inspect-first option.
What is the difference between git merge and git rebase?
Merge combines two branches by creating a new merge commit that has both histories as parents, preserving exactly what happened. Rebase replays your branch's commits one by one on top of another branch, producing a linear history with no merge commit โ cleaner to read, but it rewrites commit history, so it's best avoided on commits that have already been pushed and shared with others.
How do I undo a commit that I've already pushed?
Use git revert <commit>, which creates a new commit that undoes the changes โ safe to push, since it doesn't rewrite history others may have already pulled. Avoid git reset --hard followed by a force push on shared branches, since that rewrites history and can cause problems for anyone else who already has the old commits.
What does git stash do?
It temporarily shelves your uncommitted changes (both staged and unstaged) so you get a clean working directory โ useful when you need to switch branches without committing half-finished work. git stash pop brings those changes back later.