Git Cheat Sheets

Six printable pages: the map of where your work lives, what each command does to your history, the essentials, branches, undo & recover, and the daily loop of each team workflow. Commands with a visualization are links.

⤓ Download PDF (6 pages)⤓ This sheet

Git at a glance

The four places Git keeps your work — and exactly what each command copies between them

Gitualize
✓Safe!Rewrites history⚠Can lose work
Working directoryyour files on diskStaging areathe next commit (index)Local repositorycommits in .git, on your computerRemoteorigin — e.g. GitHubSave & shareUpdate & switchUndo✓git add <f>copies your file into staging✓git commitsaves staging as a new commit✓git pushuploads your new commits;your origin/main follows✓git commit -astages your changes to tracked files, then commits — new files still need git add✓git fetchdownloads new commits: only the origin/… branches move — your branches and files stay✓git pullfetch, then merge into your branch: your branch, staging and files update✓git switch <branch>staging and files take that branch’s version — your uncommitted edits come along, or Git refuses✓git restore --staged <f>the last commit’s version replaces the staged one = undoes git add; your file is untouched⚠git restore <f>the staged version replaces your file: its unstaged edits are lost↶ HEAD~1!git reset --soft HEAD~1only the branch moves back — nothing is copied: the commit’s changes stay staged↶ HEAD~1!git reset HEAD~1staging = the previous commit: the undone changes stay in your files, unstaged↶ HEAD~1⚠git reset --hard HEAD~1staging AND files = the previous commit: its changes and your uncommitted edits to tracked files are lost
Git copies from ● to ▶also written heresolid: towards the remote · dashed: back towards your files↶ HEAD~1your branch first moves back one commit
  • <f>a file path: type app.js, without the < >
  • HEAD~1the commit before the one you are on
  • git pullif you and the remote both have new commits, Git stops until you choose: git config pull.rebase false (merge) or true (rebase)
gitualize.com/cheatsheet 1 / 6