Git command cheatsheet

Every command used in the tutorial, what it does, and when you reach for it.

Common git commands for a first contribution
CommandWhat it doesWhen you need it
git clone <url> Downloads a full copy of a repository, including its entire history. Once, right after you fork.
git remote -v Lists the remote repositories your clone talks to. To confirm you cloned your fork and not the original.
git status Shows which files changed and which are staged for the next commit. Constantly. When unsure what state you are in, run this.
git checkout -b <name> Creates a new branch and switches to it. Before starting any change.
git switch <name> Moves to a branch that already exists. Hopping between pieces of work in progress.
git branch Lists your branches and marks the current one. When you have lost track of where you are.
git add <file> Stages one file to be included in the next commit. After editing, before committing.
git commit -m "msg" Saves everything staged as a snapshot with a message. Once per logical chunk of work.
git push -u origin <name> Uploads a branch to your fork and links the two. The first push of a new branch.
git push Uploads new commits on a branch that is already linked. Every push after the first.
git pull Downloads changes from the remote and merges them in. Before starting work, to avoid conflicts later.
git log --oneline Shows the commit history, one line per commit. Confirming your commit actually landed.
git diff Shows your unstaged changes, line by line. Reviewing your own work before you commit it.
git restore <file> Throws away uncommitted changes to a file. When an edit went wrong and you want to start over.
git restore --staged <file> Unstages a file without losing your edits. When you added the wrong file.
git commit --amend Replaces your last commit with a corrected one. Fixing a typo in the message you just wrote.

Ready to try it?

The seven-step tutorial uses these commands in order, with an explanation of what each one is doing.