Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git cheat sheet: the essential commands

All the Git commands you will use daily, sorted by usage. Keep it handy or look them up in the GitQuest app.

This cheat sheet covers the most commonly used Git commands. For detailed explanations of each command, 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
Commit

Save changes

git add <file>Add a file to staging
git add .Add all modified files
git commit -m "message"Create a commit
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
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 pushPush commits to the remote
git push -u origin <branch>Push and set up tracking
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 reflogHistory of all HEAD movements
Undo

Undo and fix

git restore <file>Discard changes to a file
git restore --staged <file>Unstage 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
Config

Configuration

git config --global user.name "Name"Set your name
git config --global user.email "email"Set your email
git tag <name>Create a tag (e.g., v1.0.0)

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.

Start the investigations