Interactive Git Cheat Sheet

🔍
git init

Create a new local Git repo

git clone [url]

Copy a repo

git add [file]

Stage changes to tracked and untracked files

git commit

Commit previously staged changes

git push origin HEAD

Push local changes to the origin

git pull

Fetch remote version and update local branch

git status

Show the status of your working directory

git help [command]

Use this when you are stuck

git branch --all

List all the local and remote branches

git checkout [branch]

Change to an existing branch

git merge [branch]

Merge branch changes into current branch

git log --graph --oneline

Show a pretty branch history

git diff

See specific local changes

git diff --ours

Compare the working tree with our branch

git diff --theirs

Compare the working tree with their branch

git archive

Create release tarball

git cherry-pick [commit-id]

Enable arbitrary Git commits to be picked by reference

git reset --hard

Reset to a specific commit (destructive)

⚠️ Destructive

Git Workflow

Working Dir
Staging
Local Repo
Remote

Git Terminology

mainDefault primary branch
originDefault upstream branch
HEADCurrent branch
HEAD^Parent of HEAD
HEAD~3Great grandparent of HEAD