Git Command Cheatsheet

Quickly find a Git command by keyword (branch, commit, rebase, stash...), organized by category, with a button to copy each command straight to your terminal.

Start

git init
Initializes a new Git repository in the current folder.
git clone <url>
Clones a remote repository into a new local folder.
git config --global user.name "Nom"
Sets the global commit author name.
git config --global user.email "email"
Sets the global commit author email.

Status & history

git status
Shows modified, added or untracked files.
git log
Shows the commit history.
git log --oneline --graph --all
Condensed history with a branch graph.
git diff
Shows unstaged changes.
git diff --staged
Shows changes that are already staged.
git show <commit>
Shows the details of a specific commit.

Edit

git add <fichier>
Adds a file to the staging area.
git add -A
Adds all modified, added and deleted files.
git commit -m "message"
Creates a commit with the staged files.
git commit --amend
Amends the last commit (message and/or content).
git restore <fichier>
Discards the unstaged changes of a file.
git restore --staged <fichier>
Removes a file from the staging area without losing its changes.
git rm <fichier>
Deletes a file and stages the deletion.

Branches

git branch
Lists local branches.
git branch <nom>
Creates a new branch.
git switch <branche>
Switches to another branch.
git switch -c <branche>
Creates a branch and switches to it immediately.
git branch -d <branche>
Deletes a local branch that has already been merged.
git branch -D <branche>
Force-deletes a local branch, even if it is not merged.

Merge & rebase

git merge <branche>
Merges a branch into the current branch.
git rebase <branche>
Replays the commits of the current branch onto another base.
git rebase -i HEAD~n
Interactive rebase of the last n commits (reorder, squash...).
git cherry-pick <commit>
Applies a specific commit to the current branch.

Remote

git remote -v
Lists the configured remote repositories.
git fetch
Fetches remote references without merging them.
git pull
Fetches and merges remote changes.
git push
Pushes local commits to the remote repository.
git push -u origin <branche>
Pushes a branch and sets it as the tracking branch.
git push --force-with-lease
Force-pushes more safely than a plain --force.

Cancel

git reset --soft HEAD~1
Undoes the last commit and keeps the changes staged.
git reset --mixed HEAD~1
Undoes the last commit and keeps the changes unstaged.
git reset --hard HEAD~1
Undoes the last commit and permanently discards its changes.
git revert <commit>
Creates a new commit that reverses the effect of a previous commit.

Stash

git stash
Temporarily sets aside your current changes.
git stash pop
Reapplies the latest stash and removes it from the list.
git stash list
Lists the saved stashes.

Labels

git tag
Lists existing tags.
git tag -a v1.0.0 -m "message"
Creates an annotated tag.
git push origin --tags
Pushes all local tags to the remote repository.

How it works

Around forty common Git commands are organized by category (getting started, state and history, branches, merge and rebase, remotes, undo, stash, tags). Type a keyword in the search bar — a command name (rebase), a concept (“undo”, “merge”) or a category — to filter the list in real time, then click “Copy” next to the command you want to paste it directly into your terminal.

What is the difference between git fetch and git pull?

git fetch downloads new references from the remote repository without changing your local branch, giving you time to inspect the changes before integrating them. git pull does the same thing and then automatically merges (or rebases, depending on your configuration) those changes into your current branch.

When should I use git reset instead of git revert?

Use git reset to rewrite the history of a branch that hasn't been shared yet (or carefully, in coordination with your team), and git revert to cleanly undo a commit that has already been pushed and may be in use by others, since it adds a new undo commit without rewriting the existing history.

This cheatsheet is completely static and works offline once the page is loaded: no data is sent to a server, including your search.