Skip to content
uxTools
Developer

Git Cheat Sheet

A searchable reference of the Git commands you reach for every day, grouped by category. Find a command, read what it does, and copy it with one click.

69

Commands

10

Categories

69

Showing

Search commands

Setup & config

7
  • git init

    Create an empty Git repository in the current directory.

    Examplegit init my-project
  • git clone <url>

    Copy a remote repository, including its full history, locally.

    Examplegit clone [email protected]:user/repo.git
  • git config --global user.name <name>

    Set the author name attached to every commit you make.

    Examplegit config --global user.name "Ada Lovelace"
  • git config --global user.email <email>

    Set the author email attached to every commit you make.

    Examplegit config --global user.email "[email protected]"
  • git config --global init.defaultBranch <name>

    Choose the default branch name used by future `git init` calls.

    Examplegit config --global init.defaultBranch main
  • git config --list

    Print every effective configuration value and where it came from.

    Examplegit config --list --show-origin
  • git config --global alias.<short> <command>

    Define a shorthand for a longer command you type often.

    Examplegit config --global alias.co "checkout"

Staging

7
  • git add <path>

    Stage changes from a file or directory for the next commit.

    Examplegit add src/index.ts
  • git add .

    Stage every change in the current directory and below.

  • git add -p

    Interactively choose which hunks of each change to stage.

  • git rm <path>

    Remove a tracked file from the tree and stage the deletion.

    Examplegit rm old-file.txt
  • git rm --cached <path>

    Stop tracking a file but keep it on disk (e.g. once gitignored).

    Examplegit rm --cached .env
  • git mv <src> <dest>

    Rename or move a tracked file and stage the change in one step.

    Examplegit mv util.ts helpers.ts
  • git restore --staged <path>

    Unstage a file, leaving its working-tree changes untouched.

    Examplegit restore --staged src/index.ts

Commit

5
  • git commit -m <message>

    Record the staged snapshot with a one-line commit message.

    Examplegit commit -m "Fix off-by-one in pager"
  • git commit -am <message>

    Stage every tracked modification and commit it in one step.

    Examplegit commit -am "Tidy up imports"
  • git commit --amend

    Rewrite the most recent commit (its message or contents).

    Examplegit commit --amend -m "Better message"
  • git commit --amend --no-edit

    Fold newly staged changes into the last commit, keeping its message.

  • git commit --allow-empty -m <message>

    Record a commit with no changes, e.g. to trigger CI.

    Examplegit commit --allow-empty -m "Trigger deploy"

Branches

8
  • git branch

    List the local branches; the current one is marked with `*`.

    Examplegit branch -a
  • git branch <name>

    Create a new branch at the current commit without switching to it.

    Examplegit branch feature/login
  • git switch <name>

    Move to an existing branch, updating the working tree.

    Examplegit switch main
  • git switch -c <name>

    Create a new branch and switch to it in one step.

    Examplegit switch -c feature/login
  • git checkout <name>

    Switch branches (the classic command; `switch` is the modern split).

    Examplegit checkout develop
  • git branch -d <name>

    Delete a branch that has already been merged.

    Examplegit branch -d feature/login
  • git branch -D <name>

    Force-delete a branch even if it has unmerged commits.

    Examplegit branch -D experiment
  • git branch -m <old> <new>

    Rename a branch (omit `<old>` to rename the current branch).

    Examplegit branch -m master main

Merge & rebase

8
  • git merge <branch>

    Join another branch's history into the current branch.

    Examplegit merge feature/login
  • git merge --no-ff <branch>

    Always create a merge commit, even for a fast-forwardable merge.

    Examplegit merge --no-ff release/1.2
  • git merge --abort

    Bail out of an in-progress merge and restore the pre-merge state.

  • git rebase <branch>

    Replay the current branch's commits on top of another branch.

    Examplegit rebase main
  • git rebase -i <ref>

    Interactively reorder, squash, edit, or drop a range of commits.

    Examplegit rebase -i HEAD~3
  • git rebase --continue

    Resume a rebase after resolving the current conflict.

  • git rebase --abort

    Cancel an in-progress rebase and return to the original state.

  • git cherry-pick <commit>

    Apply the change introduced by one commit onto the current branch.

    Examplegit cherry-pick a1b2c3d

Remotes

8
  • git remote -v

    List the configured remotes and their fetch/push URLs.

  • git remote add <name> <url>

    Register a new remote repository under a short name.

    Examplegit remote add origin [email protected]:user/repo.git
  • git fetch <remote>

    Download new objects and refs from a remote without merging.

    Examplegit fetch origin
  • git pull

    Fetch from the tracked remote branch and integrate it into yours.

    Examplegit pull --rebase
  • git push

    Upload local commits on the current branch to its remote.

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

    Push a branch and set it to track the remote for future pulls.

    Examplegit push -u origin feature/login
  • git push --force-with-lease

    Force-push safely, refusing to clobber remote work you have not seen.

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

    Delete a branch on the remote.

    Examplegit push origin --delete feature/login

Undoing things

7
  • git restore <path>

    Discard working-tree changes in a file, reverting to HEAD.

    Examplegit restore src/index.ts
  • git restore --source <ref> <path>

    Restore a file's contents from a specific commit.

    Examplegit restore --source HEAD~2 README.md
  • git reset <path>

    Unstage a file while keeping the working-tree changes.

    Examplegit reset src/index.ts
  • git reset --soft <ref>

    Move HEAD to a commit but keep changes staged.

    Examplegit reset --soft HEAD~1
  • git reset --hard <ref>

    Move HEAD and discard all staged and working-tree changes.

    Examplegit reset --hard origin/main
  • git revert <commit>

    Create a new commit that undoes a previous one, keeping history.

    Examplegit revert a1b2c3d
  • git clean -fd

    Delete untracked files and directories from the working tree.

    Examplegit clean -fdn

Stash

6
  • git stash

    Shelve uncommitted changes and revert to a clean working tree.

    Examplegit stash push -m "WIP login form"
  • git stash -u

    Stash changes including untracked files.

  • git stash list

    Show all stashed change sets you have saved.

  • git stash pop

    Reapply the most recent stash and remove it from the list.

  • git stash apply <stash>

    Reapply a stash but keep it in the list for reuse.

    Examplegit stash apply stash@{1}
  • git stash drop <stash>

    Delete a single stash from the list.

    Examplegit stash drop stash@{0}

Inspecting history

7
  • git status

    Show staged, unstaged, and untracked changes in the working tree.

    Examplegit status -s
  • git log

    Show the commit history of the current branch.

    Examplegit log --oneline --graph --all
  • git diff

    Show unstaged changes between the working tree and the index.

    Examplegit diff --staged
  • git show <ref>

    Show the metadata and diff introduced by one commit.

    Examplegit show HEAD
  • git blame <path>

    Annotate each line of a file with the commit that last changed it.

    Examplegit blame src/index.ts
  • git reflog

    List every position HEAD has pointed to — a safety net for recovery.

  • git bisect start

    Begin a binary search through history to find a regression.

    Examplegit bisect bad && git bisect good v1.0

Tags & releases

6
  • git tag

    List the existing tags in the repository.

    Examplegit tag -l "v1.*"
  • git tag <name>

    Create a lightweight tag pointing at the current commit.

    Examplegit tag v1.2.0
  • git tag -a <name> -m <message>

    Create an annotated tag with its own message and metadata.

    Examplegit tag -a v1.2.0 -m "Release 1.2.0"
  • git push <remote> <tag>

    Publish a single tag to a remote.

    Examplegit push origin v1.2.0
  • git push <remote> --tags

    Publish every local tag to a remote at once.

    Examplegit push origin --tags
  • git tag -d <name>

    Delete a local tag.

    Examplegit tag -d v1.2.0

About this sheet

Commands are drawn from the official Git reference manual and the Pro Git book. Angle brackets (like <branch>) are placeholders to swap for your own value. Nothing leaves your browser — this page is entirely client-side.