Cheatsheet Hub
Interactive cheatsheets with examples. Ask AI if you don't understand something.
Basics
8git initCreate a new local repository
git clone <url>Clone a remote repository
git statusShow working tree status
git add <file>Add files to staging area
git add .Stage all changes
git commit -m "message"Commit staged changes
git log --onelineShow commit history (compact)
git diffShow unstaged changes
Branches
9git branchList all local branches
git branch <name>Create a new branch
git checkout <name>Switch to a branch
git checkout -b <name>Create and switch to a new branch
git merge <branch>Merge branch into current
git branch -d <name>Delete a branch (safe)
git rebase <branch>Rebase current branch onto another
git switch <name>Modern way to switch branches (Git 2.23+)
git switch -c <name>Create and switch to a new branch (modern)
Remote
5git remote add origin <url>Add a remote repository
git push -u origin <branch>Push branch and set upstream
git pullFetch and merge remote changes
git fetchDownload remote changes without merging
git remote -vShow remote URLs
Undo & Fix
8git reset HEAD <file>Remove file from staging
git checkout -- <file>Discard working directory changes
git commit --amendModify the last commit
git revert <hash>Create a new commit that undoes changes
git stashTemporarily save uncommitted changes
git stash popRestore stashed changes
git restore <file>Discard working directory changes (modern, replaces checkout --)
git restore --staged <file>Remove file from staging area (modern, replaces reset HEAD)