Skip to main content
Download

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 repository
git clone <url>Clone a remote repository
git statusView the state of files
git status -sShort status, one line per file
Commit

Save changes

git add <file>Add a file to staging
git add .Add all modified files
git commit --amendEdit the last commit (message or content)
git rm <file>Delete a file and stage the deletion
git mv <old> <new>Rename or move a tracked file
git diffView unstaged changes
git diff --stagedView staged changes
Branches

Work with branches

git branchList branches
git branch <name>Create a new branch
git checkout <branch>Switch branches
git switch <branch>Switch branches (modern)
git checkout -b <name>Create and switch to a branch
git branch -d <name>Delete a merged branch
git branch -m <new-name>Rename the current branch
git worktree add <path> <branch>Check out a branch in another folder
Merge

Merge and rebase

git merge <branch>Merge a branch into the current one
git rebase <branch>Rebase onto a branch (linear history)
git rebase -i HEAD~nInteractive rebase on n commits
git merge --abortAbort a merge in progress
git cherry-pick <hash>Apply a specific commit
Remote

Work with a remote repository

git remote -vList remote repositories
git remote add origin <url>Connect a remote repository
git pushPush commits to the remote
git push -u origin <branch>Push and set up tracking
git push --force-with-leaseForce push safely after a rebase
git pullFetch and merge from the remote
git fetchFetch without merging
History

View history

git logView commit history
git log --onelineCondensed history (one line per commit)
git log --graphHistory with branch graph
git show <hash>Details of a specific commit
git blame <file>Who modified each line
git shortlog -snCount commits per author
git grep "text"Search text in tracked files
git bisect startFind the commit that introduced a bug
git reflogHistory of all HEAD movements
Undo

Undo and fix

git restore <file>Discard changes to a file
git 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 changes
git stash popRestore stashed changes
git stash listList stashed changes
git clean -fdDelete untracked files and folders
Config

Configuration

git config --listShow all your Git settings
git tag <name>Create a tag (e.g., v1.0.0)
git apply <file.patch>Apply a patch file

This cheat sheet, in your pocket

The GitQuest built-in glossary includes all these commands with interactive examples and a search engine.

Detail of a command with syntax and examples
Git command detail on iPad with examples
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.