Git Cheatsheet

Searchable reference of common Git commands for everyday work.

​
Setup & basics
git init

Create a new repository

git clone <url>

Clone a remote repository

git status

Show working tree status

git add -A

Stage all changes

git commit -m "msg"

Commit staged changes

git commit --amend

Amend the last commit

Branching
git branch

List branches

git switch -c <name>

Create and switch to a branch

git switch <name>

Switch branches

git merge <name>

Merge a branch into current

git rebase <base>

Reapply commits onto base

git branch -d <name>

Delete a branch

Remotes
git remote -v

List remotes

git fetch

Download objects/refs

git pull

Fetch and merge

git push

Upload commits

git push -u origin <br>

Push and set upstream

Undo & history
git log --oneline --graph

Compact visual history

git diff

Unstaged changes

git restore <file>

Discard working changes

git restore --staged <f>

Unstage a file

git reset --hard <ref>

Reset branch to ref (destructive)

git revert <ref>

Create a commit that undoes ref

Stash
git stash

Stash working changes

git stash pop

Reapply and drop latest stash

git stash list

List stashes

Inspect
git show <ref>

Show a commit

git blame <file>

Who changed each line

git reflog

History of HEAD moves (recovery)