Git Cheat Sheet

Essential Git commands in one page. Setup, branching, committing, merging, stashing, and undoing changes — the commands you actually use daily.

Setup & Config Basic Workflow Branching Remote Stash Undo & Reset Log & History

Setup & Config

git init Initialize a new repository
git clone <url> Clone a remote repository
git config --global user.name "Name" Set your name
git config --global user.email "email" Set your email

Basic Workflow

git status Show changed files
git add <file> Stage a file
git add . Stage all changes
git commit -m "message" Commit staged changes
git commit --amend Modify the last commit
git diff Show unstaged changes
git diff --staged Show staged changes

Branching

git branch List branches
git branch <name> Create a branch
git checkout <branch> Switch to a branch
git checkout -b <name> Create and switch to branch
git branch -d <name> Delete a branch
git merge <branch> Merge branch into current

Remote

git remote -v List remotes
git remote add origin <url> Add a remote
git push origin <branch> Push to remote
git pull Fetch and merge from remote
git fetch Fetch without merging
git push -u origin <branch> Push and set upstream

Stash

git stash Save uncommitted changes
git stash pop Apply and remove last stash
git stash list List all stashes
git stash drop Delete last stash
git stash apply stash@{n} Apply specific stash

Undo & Reset

git checkout -- <file> Discard changes in file
git reset HEAD <file> Unstage a file
git reset --soft HEAD~1 Undo last commit, keep changes staged
git reset --hard HEAD~1 Undo last commit, discard changes
git revert <commit> Create new commit that undoes a commit

Log & History

git log --oneline Compact log
git log --graph --oneline Visual branch graph
git log -p <file> Show changes to a file over time
git blame <file> Show who changed each line
git show <commit> Show commit details

More Cheat Sheets