Git cheat sheet

The Git commands you'll use every day, each explained in one line. Practice all of them in the interactive tutorial.

Start

git clone <url>Download a project and its history
git statusWhat changed? What's staged?
git log --onelineHistory, one commit per line

Save changes

git diffShow unstaged changes
git add <file>Stage a file (. for everything)
git commit -m "msg"Save a snapshot
git commit --amendRedo the last commit

Branches

git switch -c <name>Create a branch and switch to it
git switch <name>Switch branches
git merge <branch>Bring a branch into yours
git branch -d <name>Delete a merged branch

Share

git fetchDownload news, change nothing
git pullFetch + merge
git pushUpload your commits
git push -u origin <branch>Push a new branch

Undo

git restore <file>Discard uncommitted changes
git restore --staged <file>Unstage a file
git revert <commit>Undo a pushed commit safely
git reset --soft HEAD~1Undo the last commit, keep changes
git reflogFind lost commits
git stash / git stash popPut work aside / bring it back