Skip to content

Cheat sheet

Use this page when you know what you want to do and need the exact command. Short and clear. No lessons.


CommandWhat it does
git statusShows which files changed. Shows which branch you’re on. Run this a lot.
git add .Marks all changes in this folder for the next save. (You can use a file name instead of the dot.)
git commit -m "message"Saves a snapshot. The message is required. Write something short.
git pushSends your saves to the internet (for example GitHub).
git pullGets saves from the internet and puts them in your folder.

Branches (when you want a separate line of work)

Section titled “Branches (when you want a separate line of work)”
CommandWhat it does
git branchLists your branches.
git branch nameCreates a branch with that name. You’re still on the old branch.
git switch nameSwitches to that branch. (Use this one.)
git switch -c nameCreates the branch and switches to it. One step.
git merge namePuts that branch’s changes into the branch you’re on.

CommandWhat it does
git logShows the list of commits. Press q to quit.
git log --onelineSame list but one line per commit.
git diffShows line-by-line what you changed (only files you didn’t add yet).
git diff --stagedShows line-by-line what you added and will commit.

CommandWhat it does
git clone urlCopies a repo from the internet to your computer.
git initMakes this folder a Git repo. Do it once per project.
git remote -vShows the internet address (for example origin).

CommandWhat it does
git restore fileThrows away your changes in that file. File goes back to last commit.
git restore --staged fileUn-stages the file. The file still has your changes.
git stashPuts your changes aside for a bit. Your folder looks like the last commit.
git stash popBrings the stashed changes back.