Git commands cheat sheet: the essential list
The Git commands you will use every day, sorted by usage: setup, commit, branches, remote, history and undo. Click a command to see it explained with examples.
By Anaïs Sparesotto, web developer and head of education · Updated
This list covers the most commonly used Git commands. Each linked command opens a full guide with syntax, examples and common mistakes. For definitions, see the full Git glossary.
Basics
Start a project
git initInitialize a new Git repositorygit clone <url>Clone a remote repositorygit statusView the state of filesgit status -sShort status, one line per fileCommit
Save changes
git add <file>Add a file to staginggit add .Add all modified filesgit commit -m "message"Create a commitgit commit --amendEdit the last commit (message or content)git rm <file>Delete a file and stage the deletiongit mv <old> <new>Rename or move a tracked filegit diffView unstaged changesgit diff --stagedView staged changesBranches
Work with branches
git branchList branchesgit branch <name>Create a new branchgit checkout <branch>Switch branchesgit switch <branch>Switch branches (modern)git checkout -b <name>Create and switch to a branchgit branch -d <name>Delete a merged branchgit branch -m <new-name>Rename the current branchgit worktree add <path> <branch>Check out a branch in another folderMerge
Merge and rebase
git merge <branch>Merge a branch into the current onegit rebase <branch>Rebase onto a branch (linear history)git rebase -i HEAD~nInteractive rebase on n commitsgit merge --abortAbort a merge in progressgit cherry-pick <hash>Apply a specific commitRemote
Work with a remote repository
git remote -vList remote repositoriesgit remote add origin <url>Connect a remote repositorygit pushPush commits to the remotegit push -u origin <branch>Push and set up trackinggit push --force-with-leaseForce push safely after a rebasegit pullFetch and merge from the remotegit fetchFetch without mergingHistory
View history
git logView commit historygit log --onelineCondensed history (one line per commit)git log --graphHistory with branch graphgit show <hash>Details of a specific commitgit blame <file>Who modified each linegit shortlog -snCount commits per authorgit grep "text"Search text in tracked filesgit bisect startFind the commit that introduced a buggit reflogHistory of all HEAD movementsUndo
Undo and fix
git restore <file>Discard changes to a filegit restore --staged <file>Unstage a filegit reset --soft HEAD~1Undo last commit (keep changes)git reset --hard HEAD~1Undo last commit (discard everything)git revert <hash>Create a reverse commit (safe)git stashSet aside current changesgit stash popRestore stashed changesgit stash listList stashed changesgit clean -fdDelete untracked files and foldersConfig
Configuration
git config --global user.name "Name"Set your namegit config --global user.email "email"Set your emailgit config --listShow all your Git settingsgit tag <name>Create a tag (e.g., v1.0.0)git apply <file.patch>Apply a patch fileThis cheat sheet, in your pocket
The GitQuest built-in glossary includes all these commands with interactive examples and a search engine.


A
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Memorizing is good. Practicing is better.
The cheat sheet helps you find a command. GitQuest investigations help you master it.
