Git Command Cheatsheet

Quick reference for common Git commands, covering basics, branching, remotes, undo, and more. 100% free, no signup, runs locally in your browser—nothing is uploaded to our servers.

Basic

git initInitialize a new repositoryClick to copy
git clone <url>Clone a remote repositoryClick to copy
git statusShow working tree statusClick to copy
git add <file>Stage file(s) for commitClick to copy
git add .Stage all changesClick to copy
git commit -m "msg"Commit staged changesClick to copy
git diffShow unstaged changesClick to copy
git diff --stagedShow staged changesClick to copy

Branch

git branchList local branchesClick to copy
git branch <name>Create a new branchClick to copy
git checkout <branch>Switch to branchClick to copy
git checkout -b <name>Create & switch to branchClick to copy
git switch <branch>Switch to branch (new)Click to copy
git switch -c <name>Create & switch (new)Click to copy
git merge <branch>Merge branch into currentClick to copy
git branch -d <name>Delete a branchClick to copy
git branch -m <old> <new>Rename a branchClick to copy

Remote

git remote -vList remote repositoriesClick to copy
git remote add <name> <url>Add a remoteClick to copy
git fetchFetch from remoteClick to copy
git pullFetch & mergeClick to copy
git pushPush to remoteClick to copy
git push -u origin <branch>Push & set upstreamClick to copy
git remote remove <name>Remove a remoteClick to copy

Undo/Reset

git reset HEAD <file>Unstage a fileClick to copy
git checkout -- <file>Discard working changesClick to copy
git restore <file>Discard working changes (new)Click to copy
git reset --soft HEAD~1Undo last commit, keep stagedClick to copy
git reset --mixed HEAD~1Undo last commit, keep unstagedClick to copy
git reset --hard HEAD~1Undo last commit, discard allClick to copy
git revert <commit>Create undo commitClick to copy

Stash

git stashStash current changesClick to copy
git stash listList stashesClick to copy
git stash popApply & remove latest stashClick to copy
git stash applyApply latest stashClick to copy
git stash dropRemove latest stashClick to copy
git stash push -m "msg"Stash with a messageClick to copy

Log

git logShow commit historyClick to copy
git log --onelineCompact commit historyClick to copy
git log --graphGraph of branchesClick to copy
git log -n <count>Show last N commitsClick to copy
git show <commit>Show commit detailsClick to copy
git blame <file>Line-by-line historyClick to copy

Tag

git tagList tagsClick to copy
git tag <name>Create lightweight tagClick to copy
git tag -a <name> -m "msg"Create annotated tagClick to copy
git tag -d <name>Delete a tagClick to copy
git push origin --tagsPush tags to remoteClick to copy