Git Command Generator

Search commands, build complex operations, and follow workflow templates. Click any command to copy.

S

Setup

(5)
git init

Initialize a new Git repository in the current directory

Example: git init
git clone <url>

Clone a remote repository to your local machine

Example: git clone https://github.com/user/repo.git
git config --global user.name "<name>"

Set your name for all repositories

Example: git config --global user.name "Jane Doe"
git config --global user.email "<email>"

Set your email for all repositories

Example: git config --global user.email "[email protected]"
git config --list

Show all Git configuration settings

Example: git config --list
B

Basics

(8)
git status

Show the status of your working directory and staging area

Example: git status
git add <file>

Stage a specific file for commit

Example: git add src/app.js
git add .

Stage all changes in the current directory

Example: git add .
git add -p

Interactively stage hunks of changes

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

Commit staged changes with a message

Example: git commit -m "Add login feature"
git commit --amend

Modify the last commit (message or staged files)

Example: git commit --amend -m "Updated message"
git rm <file>

Remove a file from the working tree and stage the deletion

Example: git rm old-file.txt
git mv <old> <new>

Rename or move a file and stage the change

Example: git mv old-name.js new-name.js
Y

Branching

(9)
git branch

List all local branches

Example: git branch
git branch -a

List all local and remote branches

Example: git branch -a
git branch <name>

Create a new branch (does not switch to it)

Example: git branch feature/login
git checkout -b <name>

Create a new branch and switch to it

Example: git checkout -b feature/login
git switch <name>

Switch to an existing branch

Example: git switch main
git switch -c <name>

Create and switch to a new branch (modern syntax)

Example: git switch -c feature/login
git branch -d <name>

Delete a branch (safe, prevents deleting unmerged)

Example: git branch -d feature/login
git branch -D <name>

Force delete a branch even if unmerged

Example: git branch -D feature/login
git branch -m <old> <new>

Rename a branch

Example: git branch -m old-name new-name
M

Merging

(8)
git merge <branch>

Merge a branch into the current branch

Example: git merge feature/login
git merge --no-ff <branch>

Merge with a merge commit even if fast-forward is possible

Example: git merge --no-ff feature/login
git merge --squash <branch>

Squash all commits from branch into a single staged change

Example: git merge --squash feature/login
git merge --abort

Abort a merge in progress and return to pre-merge state

Example: git merge --abort
git rebase <branch>

Rebase current branch onto another branch

Example: git rebase main
git rebase -i HEAD~<n>

Interactive rebase to edit, squash, or reorder last N commits

Example: git rebase -i HEAD~3
git rebase --abort

Abort a rebase in progress

Example: git rebase --abort
git rebase --continue

Continue a rebase after resolving conflicts

Example: git rebase --continue
R

Remote

(10)
git remote -v

List all configured remote repositories

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

Add a new remote repository

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

Remove a remote

Example: git remote remove origin
git push <remote> <branch>

Push a branch to a remote repository

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

Push and set the upstream tracking branch

Example: git push -u origin feature/login
git push --force

Force push, overwriting remote history (use with caution)

Example: git push --force origin feature/login
git pull <remote> <branch>

Fetch and merge changes from a remote branch

Example: git pull origin main
git pull --rebase

Fetch and rebase instead of merging

Example: git pull --rebase origin main
git fetch <remote>

Download objects and refs from remote without merging

Example: git fetch origin
git fetch --prune

Fetch and remove refs to deleted remote branches

Example: git fetch --prune origin
$

Stashing

(8)
git stash

Stash uncommitted changes for later

Example: git stash
git stash push -m "<message>"

Stash with a descriptive message

Example: git stash push -m "WIP: login form"
git stash list

List all stashes

Example: git stash list
git stash pop

Apply the most recent stash and remove it from the list

Example: git stash pop
git stash apply

Apply the most recent stash but keep it in the list

Example: git stash apply
git stash drop

Delete the most recent stash

Example: git stash drop
git stash drop stash@{<n>}

Delete a specific stash by index

Example: git stash drop stash@{2}
git stash clear

Delete all stashes

Example: git stash clear
H

History

(12)
git log

Show commit history

Example: git log
git log --oneline

Show compact commit history (one line per commit)

Example: git log --oneline
git log --oneline --graph

Show commit history as a graph

Example: git log --oneline --graph --all
git log -n <number>

Show only the last N commits

Example: git log -n 5
git log --author="<name>"

Show commits by a specific author

Example: git log --author="Jane"
git log -- <file>

Show commit history for a specific file

Example: git log -- src/app.js
git diff

Show unstaged changes in the working directory

Example: git diff
git diff --staged

Show staged changes (ready to commit)

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

Compare two branches

Example: git diff main feature/login
git blame <file>

Show who last modified each line of a file

Example: git blame src/app.js
git show <commit>

Show details and diff for a specific commit

Example: git show abc1234
git reflog

Show a log of all reference changes (useful for recovery)

Example: git reflog
U

Undoing Changes

(10)
git restore <file>

Discard changes in working directory (restore from staging)

Example: git restore src/app.js
git restore --staged <file>

Unstage a file (keep working directory changes)

Example: git restore --staged src/app.js
git reset --soft HEAD~1

Undo last commit, keep changes staged

Example: git reset --soft HEAD~1
git reset HEAD~1

Undo last commit, unstage changes (keep in working dir)

Example: git reset HEAD~1
git reset --hard HEAD~1

Undo last commit and discard all changes permanently

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

Reset branch to a specific commit, discard everything after

Example: git reset --hard abc1234
git revert <commit>

Create a new commit that undoes a specific commit

Example: git revert abc1234
git cherry-pick <commit>

Apply a specific commit from another branch

Example: git cherry-pick abc1234
git cherry-pick -n <commit>

Apply commit changes without auto-committing

Example: git cherry-pick -n abc1234
git clean -fd

Remove untracked files and directories

Example: git clean -fd
T

Tags

(8)
git tag

List all tags

Example: git tag
git tag <name>

Create a lightweight tag at the current commit

Example: git tag v1.0.0
git tag -a <name> -m "<message>"

Create an annotated tag with a message

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

Tag a specific commit

Example: git tag -a v1.0.0 abc1234
git push <remote> <tag>

Push a specific tag to remote

Example: git push origin v1.0.0
git push <remote> --tags

Push all tags to remote

Example: git push origin --tags
git tag -d <name>

Delete a local tag

Example: git tag -d v1.0.0
git push <remote> :refs/tags/<name>

Delete a remote tag

Example: git push origin :refs/tags/v1.0.0
A

Advanced

(10)
git bisect start

Start a binary search to find a commit that introduced a bug

Example: git bisect start
git bisect bad

Mark the current commit as bad (has bug)

Example: git bisect bad
git bisect good <commit>

Mark a known good commit

Example: git bisect good abc1234
git bisect reset

End bisect session and return to original branch

Example: git bisect reset
git worktree add <path> <branch>

Create a linked working tree for a branch

Example: git worktree add ../hotfix hotfix/urgent
git submodule add <url>

Add a Git submodule to the repository

Example: git submodule add https://github.com/lib/util.git
git submodule update --init --recursive

Initialize and update all submodules

Example: git submodule update --init --recursive
git shortlog -sn

Show commit count per author, sorted

Example: git shortlog -sn
git log --all --oneline --graph --decorate

Visual branch graph with decorations

Example: git log --all --oneline --graph --decorate
git archive --format=zip HEAD -o repo.zip

Create a zip archive of the current HEAD

Example: git archive --format=zip HEAD -o repo.zip

Get the JSON & API Cheat Sheet

Formatting tricks, jq commands, and common patterns — one page, zero fluff.

Git Commands Cheat Sheet

Git has hundreds of commands and flags, but most developers use the same 20-30 regularly. This Git command reference covers the commands you'll actually need — from everyday basics like commit, push, and pull to situational lifesavers like reflog, cherry-pick, and bisect.

The reference is organized by workflow rather than alphabetically, because you usually think "I need to undo something" not "I need a command that starts with R." Sections cover branching, committing, undoing changes, working with remotes, inspecting history, and advanced operations like interactive rebase and stash management.

Every command includes the most common flags and a brief explanation of when you'd use it. This is designed to be a quick-reference tool you keep open while working, not a comprehensive Git textbook. Bookmark it for the next time you need to remember the difference between reset --soft, reset --mixed, and reset --hard.

Tips

  • Use git log --oneline --graph --all to visualize your branch structure — it's the fastest way to understand what happened.
  • git stash saves uncommitted changes temporarily. Use git stash pop to restore them. Add -u to include untracked files.
  • git reflog is your safety net — it records every HEAD movement, so you can recover from almost any mistake.
  • Set up aliases for common commands: git config --global alias.co checkout saves keystrokes every day.