Git Cheat Sheet

Essential Git commands quick reference. Search, browse, and copy commands for setup, branching, merging, stashing, undoing changes, and more.

105 commands across 9 categories

|
git config --global user.name "Name"

Set your global username for commits

git config --global user.name "John Doe"
git config --global user.email "email"

Set your global email for commits

git config --global user.email "john@example.com"
git config --list

List all Git configuration settings

git config --list
git config --global core.editor "code"

Set default text editor for Git

git config --global core.editor "vim"
git config --global init.defaultBranch main

Set default branch name for new repos

git config --global init.defaultBranch main
git config --global alias.<name> "<cmd>"

Create a shortcut alias for a Git command

git config --global alias.co "checkout"
git init

Initialize a new Git repository in the current directory

cd my-project && git init
git init <directory>

Create a new repo in the specified directory

git init my-new-project
git clone <url>

Clone a remote repository to your local machine

git clone https://github.com/user/repo.git
git clone <url> <directory>

Clone a repo into a specific folder name

git clone https://github.com/user/repo.git my-folder
git clone --depth 1 <url>

Shallow clone with only the latest commit

git clone --depth 1 https://github.com/user/repo.git
git clone --branch <branch> <url>

Clone a specific branch from a repository

git clone --branch develop https://github.com/user/repo.git
git add <file>

Add a file to the staging area

git add index.html
git add .

Stage all changes in the current directory

git add .
git add -A

Stage all changes including deletions

git add -A
git add -p

Interactively stage parts of files (hunks)

git add -p
git commit -m "<message>"

Commit staged changes with a message

git commit -m "Add login feature"
git commit -am "<message>"

Stage tracked files and commit in one step

git commit -am "Fix typo in header"
git commit --amend

Modify the most recent commit

git commit --amend -m "Updated commit message"
git status

Show the working tree status

git status
git status -s

Show status in short format

git status -s
git diff

Show unstaged changes in working directory

git diff
git diff --staged

Show changes staged for the next commit

git diff --staged
git diff <branch1> <branch2>

Show differences between two branches

git diff main develop
git rm <file>

Remove a file from tracking and working directory

git rm old-file.txt
git rm --cached <file>

Remove a file from staging but keep it locally

git rm --cached secrets.env
git mv <old> <new>

Rename or move a file and stage the change

git mv old-name.js new-name.js
git branch

List all local branches

git branch
git branch -a

List all local and remote branches

git branch -a
git branch <name>

Create a new branch

git branch feature-login
git branch -d <name>

Delete a branch (safe, prevents unmerged deletion)

git branch -d feature-login
git branch -D <name>

Force delete a branch even if unmerged

git branch -D experimental
git branch -m <new>

Rename the current branch

git branch -m new-branch-name
git checkout <branch>

Switch to an existing branch

git checkout develop
git checkout -b <branch>

Create and switch to a new branch

git checkout -b feature-signup
git switch <branch>

Switch to an existing branch (modern)

git switch develop
git switch -c <branch>

Create and switch to a new branch (modern)

git switch -c feature-dashboard
git merge <branch>

Merge a branch into the current branch

git merge feature-login
git merge --no-ff <branch>

Merge with a merge commit even if fast-forward possible

git merge --no-ff feature-login
git merge --abort

Abort an in-progress merge and restore pre-merge state

git merge --abort
git rebase <branch>

Reapply commits on top of another base branch

git rebase main
git rebase --abort

Abort an in-progress rebase

git rebase --abort
git rebase --continue

Continue rebase after resolving conflicts

git rebase --continue
git cherry-pick <commit>

Apply a specific commit to the current branch

git cherry-pick a1b2c3d
git remote -v

List all remote repositories with URLs

git remote -v
git remote add <name> <url>

Add a new remote repository

git remote add origin https://github.com/user/repo.git
git remote remove <name>

Remove a remote repository

git remote remove origin
git remote rename <old> <new>

Rename a remote repository

git remote rename origin upstream
git fetch

Download objects and refs from remote without merging

git fetch origin
git fetch --all

Fetch from all configured remotes

git fetch --all
git fetch --prune

Fetch and remove deleted remote tracking branches

git fetch --prune
git pull

Fetch and merge changes from remote branch

git pull origin main
git pull --rebase

Fetch and rebase instead of merge

git pull --rebase origin main
git push

Push committed changes to the remote repository

git push origin main
git push -u <remote> <branch>

Push and set upstream tracking branch

git push -u origin feature-login
git push --force

Force push (overwrites remote history, use with caution)

git push --force origin feature-branch
git push --tags

Push all local tags to the remote

git push --tags
git push <remote> --delete <branch>

Delete a remote branch

git push origin --delete feature-old
git log

Show the commit history

git log
git log --oneline

Show commit history in compact one-line format

git log --oneline
git log --graph

Show commit history with ASCII branch graph

git log --graph --oneline --all
git log --author="<name>"

Filter commit history by author

git log --author="John"
git log -n <number>

Show only the last n commits

git log -n 5
git log --since="<date>"

Show commits after a specific date

git log --since="2024-01-01"
git log -p <file>

Show commit history with diffs for a file

git log -p README.md
git show <commit>

Show details and diff of a specific commit

git show a1b2c3d
git blame <file>

Show who last modified each line of a file

git blame index.html
git shortlog -sn

Show commit count per author sorted by count

git shortlog -sn
git reflog

Show history of HEAD changes (useful for recovery)

git reflog
git bisect start

Start binary search to find a buggy commit

git bisect start
git bisect bad

Mark the current commit as bad during bisect

git bisect bad
git bisect good <commit>

Mark a commit as good during bisect

git bisect good a1b2c3d
git bisect reset

End the bisect session and return to original branch

git bisect reset
git stash

Save uncommitted changes and clean working directory

git stash
git stash save "<message>"

Stash changes with a descriptive message

git stash save "work in progress on login"
git stash list

List all stashed changesets

git stash list
git stash pop

Apply the most recent stash and remove it from list

git stash pop
git stash apply

Apply the most recent stash but keep it in list

git stash apply
git stash apply stash@{n}

Apply a specific stash by index

git stash apply stash@{2}
git stash drop

Remove the most recent stash from list

git stash drop
git stash drop stash@{n}

Remove a specific stash by index

git stash drop stash@{1}
git stash clear

Remove all stashed entries

git stash clear
git stash branch <branch>

Create a new branch from a stash

git stash branch feature-from-stash
git restore <file>

Discard changes in working directory (modern)

git restore index.html
git restore --staged <file>

Unstage a file while keeping changes (modern)

git restore --staged index.html
git checkout -- <file>

Discard changes in working directory (classic)

git checkout -- index.html
git reset <file>

Unstage a file while keeping changes

git reset README.md
git reset --soft HEAD~1

Undo last commit but keep changes staged

git reset --soft HEAD~1
git reset --mixed HEAD~1

Undo last commit and unstage changes

git reset --mixed HEAD~1
git reset --hard HEAD~1

Undo last commit and discard all changes

git reset --hard HEAD~1
git reset --hard <commit>

Reset branch to a specific commit (destructive)

git reset --hard a1b2c3d
git revert <commit>

Create a new commit that undoes a previous commit

git revert a1b2c3d
git revert HEAD

Revert the most recent commit

git revert HEAD
git clean -f

Remove untracked files from working directory

git clean -f
git clean -fd

Remove untracked files and directories

git clean -fd
git clean -n

Dry run: show what would be removed

git clean -n
git tag

List all tags in the repository

git tag
git tag <name>

Create a lightweight tag at the current commit

git tag v1.0.0
git tag -a <name> -m "<msg>"

Create an annotated tag with a message

git tag -a v1.0.0 -m "Release version 1.0.0"
git tag -a <name> <commit>

Tag a specific commit

git tag -a v0.9.0 a1b2c3d
git tag -d <name>

Delete a local tag

git tag -d v1.0.0
git push origin <tag>

Push a specific tag to remote

git push origin v1.0.0
git push --tags

Push all local tags to the remote

git push --tags
git push origin --delete <tag>

Delete a remote tag

git push origin --delete v1.0.0
git show <tag>

Show information about a tag

git show v1.0.0

What Is Git?

Git is the most widely used distributed version control system in the world. Created by Linus Torvalds in 2005 for Linux kernel development, Git tracks changes in source code and enables multiple developers to collaborate on projects of any size. It is the foundation of platforms like GitHub, GitLab, and Bitbucket.

How to Use This Git Cheat Sheet

This cheat sheet organizes essential Git commands into logical categories. Use the search bar to quickly find any command by name, description, or example. Click Copy on any command to copy it to your clipboard. Expand or collapse sections to focus on the commands you need.

Git Workflow Basics

A typical Git workflow involves creating a branch for a new feature (git checkout -b feature), making changes, staging them (git add .), committing (git commit -m "message"), pushing to a remote (git push), and then creating a pull request to merge your changes back into the main branch.

Git Branching Strategies

Common branching strategies include Git Flow (with develop, feature, release, and hotfix branches), GitHub Flow (simple feature branches merged to main), and Trunk-Based Development (short-lived branches with frequent merges). Choose the strategy that best fits your team size and release cadence.

Tips for Using Git Effectively

  • Write clear, descriptive commit messages that explain why a change was made.
  • Commit early and commit often — small commits are easier to review and revert.
  • Use branches for every feature, bugfix, or experiment.
  • Pull frequently to stay up to date and reduce merge conflicts.
  • Use git stash to save work in progress before switching branches.
  • Always review changes with git diff before committing.
  • Use .gitignore to exclude build artifacts, dependencies, and sensitive files.
  • Learn git reflog — it can save you when things go wrong.

Frequently Asked Questions

Is the Git Cheat Sheet free to use?

Yes, the Git Cheat Sheet is completely free with no usage limits. There is no signup or registration required. You can use it as many times as you need.

Is my data safe when using this tool?

Yes. All processing happens locally in your browser using JavaScript. Your data is never uploaded to any server or stored anywhere. Everything stays on your device.

Does this tool work on mobile devices?

Yes. The Git Cheat Sheet is fully responsive and works on smartphones, tablets, and desktop computers. You can use it from any modern browser on any device.

Do I need to install anything?

No. The Git Cheat Sheet runs entirely in your web browser. There is nothing to download or install. Just open the page and start using it immediately.