Setup
git initInitialize a new local repositorygit clone <url>Clone a repository from remotegit config --global user.name 'Name'Set global usernamegit config --global user.email 'email'Set global emailBasics
git statusShow working tree statusgit add <file>Stage a specific filegit add .Stage all changesgit commit -m 'msg'Commit staged changesgit diffShow unstaged changesgit diff --stagedShow staged changesgit log --onelineCompact commit historyBranching
git branchList all local branchesgit branch <name>Create a new branchgit checkout <branch>Switch to a branchgit checkout -b <branch>Create and switch to new branchgit branch -d <branch>Delete a branchgit switch <branch>Switch branches (modern syntax)Merging
git merge <branch>Merge a branch into currentgit rebase <branch>Rebase current branch onto anothergit cherry-pick <hash>Apply a specific commitgit merge --abortAbort a merge in progressRemote
git remote add origin <url>Add a remote repositorygit push origin <branch>Push branch to remotegit pullFetch and merge from remotegit fetchFetch from remote without merginggit push --tagsPush all tags to remoteUndo
git reset HEAD <file>Unstage a filegit checkout -- <file>Discard changes in working directorygit revert <hash>Revert a commit (safe)git reset --hard HEAD~1Delete last commit (destructive)git clean -fdRemove untracked files/dirsStash
git stashStash current changesgit stash popApply most recent stashgit stash listList all stashesgit stash dropDelete most recent stash