Cheat sheets / Git

Git Cheat Sheet

The 36 Git commands that cover everyday work: seeing what changed, committing, branching, syncing, and getting out of trouble. Click a command to copy it.

This page also works as a hotkey overlay. Hold Ctrl+Space to see it, let go to hide it. What is this?

See what's going on

Stage and commit

Amending rewrites the last commit. That's fine before you push; after a push it needs a force push.

Branches

Work with a remote

--force-with-lease refuses to overwrite commits you haven't fetched, which plain --force happily does.

Merge and rebase

Undo and rescue

restore and reset --hard destroy uncommitted work and Git cannot bring it back. Committed work is safer: git reflog still lists it for at least 30 days.

Parts in {{double braces}} are blanks: click the command and you type the value before it is copied. git switch and git restore need Git 2.23 or newer (2019). On an older Git, git checkout does both jobs.

Keep this cheat sheet on a hotkey

BrainRAM is a small free app for Windows. Hold Ctrl+Space and this page appears on top of whatever you are doing. Let go and it's gone. Click a cell and it's copied.

Each row is one topic, named at its left edge, in the same order as this page. So undo and rescue is always the bottom row, and after a few days you stop reading and just reach for the spot.

Cells with a blank, like {{commit}}, ask you for the value first and copy the finished command, the same way they do on this page.

  1. Download BrainRAM Free, no account, works offline. The installer isn't code-signed yet, so Windows shows a blue warning: click More info, then Run anyway.
  2. Add this page to BrainRAM Opens BrainRAM with this page ready to import.

BrainRAM runs on Windows today. The macOS and Linux versions are on the way.

Email me when mine is ready
This page as BrainRAM shows it while you hold the hotkey.

More cheat sheets


      
Enter continue · Esc cancel