Git commands

Distributed version control system

492 commands

Setup & Config

  • git init

    Initialize a new, empty Git repository in the current directory

  • git init <directory>

    Create a new directory and initialize a Git repository within it

  • git init --bare

    Initialize a bare repository without a working directory

  • git init --bare <directory>

    Create a new bare repository in the specified directory

  • git init -b <branch-name>

    Initialize a repository with a custom initial branch name

  • git init --initial-branch=<branch-name>

    Initialize a repository, explicitly setting the starting branch

  • git clone <url>

    Clone a remote repository to your local machine

  • git clone <url> <directory>

    Clone a remote repository into a specific target directory

  • git clone --depth 1 <url>

    Perform a shallow clone downloading only the latest commits

  • git clone --branch <branch> <url>

    Clone a repository and checkout a specific branch immediately

  • git clone --single-branch <url>

    Clone a repository fetching only the history of the default branch

  • git clone --no-single-branch <url>

    Clone fetching history for all branches

  • git clone --recurse-submodules <url>

    Clone a repository and automatically initialize/update its submodules

  • git clone --bare <url>

    Clone a repository as a bare repository without a working tree

  • git clone --mirror <url>

    Create a mirror clone suitable for backup or migrating servers

  • git clone --quiet <url>

    Clone a repository silently without showing progress output

  • git clone --verbose <url>

    Clone a repository displaying detailed debug output

  • git clone --origin <name> <url>

    Clone and use a custom name instead of 'origin' for the remote

  • git clone --depth 1 --branch <branch> <url>

    Shallow clone only the latest commit of a specific branch

  • git clone --depth 1 --single-branch --branch <branch> <url>

    Shallow clone strictly isolated to a single branch

  • git config --list

    List all Git configuration settings applied in the current scope

  • git config --global --list

    List global Git configuration settings for the current user

  • git config --local --list

    List configuration settings specific to the current repository

  • git config --system --list

    List system-wide Git configuration settings

  • git config <key>

    Read the value of a specific Git configuration key

  • git config --global <key>

    Read the value of a global Git configuration key

  • git config <key> <value>

    Set a specific configuration key to a value in the local repo

  • git config --global <key> <value>

    Set a global Git configuration key to a value

  • git config --global user.name "<name>"

    Set the default author name for your commits globally

  • git config --global user.email "<email>"

    Set the default author email for your commits globally

  • git config --global core.editor <editor>

    Set the default text editor for Git commands globally

  • git config --global init.defaultBranch <name>

    Set the default branch name for newly initialized repositories

  • git config --global pull.rebase true

    Configure Git to rebase by default when pulling changes

  • git config --global push.default current

    Set Git to push only the current branch to its remote counterpart

  • git config --global alias.<alias> <command>

    Create a global shortcut alias for a Git command

  • git config --unset <key>

    Remove a specific configuration key from the local repository

  • git config --global --unset <key>

    Remove a global configuration key

  • git config --edit

    Open the local Git configuration file in the default editor

  • git config --global --edit

    Open the global Git configuration file in the default editor

  • git config --add <key> <value>

    Add a value to a multi-valued configuration key

  • git config --get-all <key>

    Get all values assigned to a multi-valued configuration key

  • git clone <file> <directory>

    Clone a local repository path into a new directory

Staging & Snapshots

  • git add <file>

    Stage a specific file's changes for the next commit

  • git add .

    Stage all new and modified files in the current directory

  • git add -A

    Stage all changes, including deletions, across the entire working tree

  • git add --all

    Stage everything: modifications, new files, and deletions

  • git add -p

    Interactively stage specific chunks (hunks) of changes

  • git add --patch

    Interactively choose which parts of files to stage

  • git add -u

    Stage modifications and deletions, but ignore new untracked files

  • git add --update

    Update the index just for files that are already tracked

  • git add -n

    Dry run: show what files would be staged without actually staging them

  • git add --dry-run

    Simulate adding files to preview changes

  • git add -f <file>

    Force add a file that is otherwise ignored by .gitignore

  • git add --force <file>

    Forcefully stage an ignored file

  • git add -i

    Open the interactive staging prompt menu

  • git add --interactive

    Start an interactive session to manage the staging area

  • git add -e

    Open the diff in an editor to manually edit what gets staged

  • git add --edit

    Manually edit the patch file before staging it

  • git add *.js

    Stage all files matching a specific extension (e.g., .js)

  • git add <dir>/

    Stage all modified and new files within a specific directory

  • git commit

    Create a commit containing staged changes, opening the editor for a message

  • git commit -m "<message>"

    Create a commit with a single-line message

  • git commit -a

    Automatically stage all modified tracked files and open editor to commit

  • git commit -am "<message>"

    Automatically stage modified tracked files and commit with a message

  • git commit --amend

    Combine staged changes with the previous commit and edit the message

  • git commit --amend -m "<message>"

    Combine staged changes with previous commit and replace the message

  • git commit --amend --no-edit

    Add staged changes to the previous commit without altering its message

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

    Create a commit even if there are no staged changes

  • git commit --no-verify -m "<message>"

    Commit while bypassing pre-commit and commit-msg hooks

  • git commit -S -m "<message>"

    Create a GPG-signed commit

  • git commit --gpg-sign -m "<message>"

    Force GPG signature for the commit

  • git commit --author="<name> <email>" -m "<message>"

    Commit with a custom overridden author name and email

  • git commit --date="<date>" -m "<message>"

    Commit specifying a custom timestamp

  • git commit -v

    Open editor with the diff of what is being committed visible

  • git commit --verbose

    Show the full unified diff in the commit message editor

  • git commit -q

    Commit quietly, suppressing standard summary output

  • git commit --quiet

    Commit with minimal output to console

  • git commit -m "<message>" -m "<body>"

    Commit with a subject line and a separate body paragraph

  • git commit --squash <commit>

    Create a commit marked to be squashed into a specific older commit

  • git commit --fixup <commit>

    Create a commit meant to invisibly fix an older commit during rebase

  • git status

    Show the state of the working directory and staging area

  • git status -s

    Show status in a concise short format

  • git status --short

    Display shortened status output

  • git status -b

    Show current branch tracking info alongside short status

  • git status --branch

    Include branch tracking information in the output

  • git status -sb

    Show concise short status alongside branch info

  • git status --porcelain

    Output machine-readable status meant for parsing by scripts

  • git status -u

    Show untracked files explicitly in the output

  • git status --untracked-files=all

    List untracked files and untracked directories contents individually

  • git status --ignored

    Show status and also list ignored files

  • git status --ahead-behind

    Calculate and display how far ahead or behind the remote branch is

  • git diff

    Show unstaged changes in the working directory

  • git diff <file>

    Show unstaged changes for a specific file

  • git diff --staged

    Show changes that are currently staged for the next commit

  • git diff --cached

    Alias for --staged, showing changes ready to be committed

  • git diff HEAD

    Show all changes (staged and unstaged) since the last commit

  • git diff HEAD~1

    Show changes between the working tree and the previous commit

  • git diff <branch1> <branch2>

    Show the differences between two branches

  • git diff <commit1> <commit2>

    Show the differences between two specific commits

  • git diff --stat

    Show a summary of lines added/removed instead of the full diff

  • git diff --name-only

    Output only the names of the files that changed

  • git diff --name-status

    Output filenames and their modification status (Added, Modified, etc.)

  • git diff --word-diff

    Show differences at the word level instead of line-by-line

  • git diff --color

    Force colored output for diffs

  • git diff --no-color

    Disable colored output for diffs

  • git diff -U<n>

    Generate diffs with <n> lines of context

  • git diff --unified=<n>

    Set the number of unified diff context lines

  • git diff --ignore-space-change

    Ignore changes in amount of whitespace

  • git diff -w

    Completely ignore all whitespace when comparing lines

  • git diff --ignore-all-space

    Ignore whitespace differences completely

  • git diff --diff-filter=<filter>

    Filter diffs by file state (e.g., A for added, D for deleted)

  • git diff HEAD --name-only

    List names of all files changed since the last commit

  • git diff --staged --stat

    Show a summary of the changes staged for the next commit

  • git stash

    Temporarily save unstaged and staged changes in a stack

  • git stash push

    Explicitly push current changes onto the stash stack

  • git stash push -m "<message>"

    Stash current changes with a specific descriptive message

  • git stash push -u

    Stash tracked file changes along with untracked files

  • git stash push --include-untracked

    Include untracked files when stashing changes

  • git stash push -a

    Stash all changes, including untracked and ignored files

  • git stash push --all

    Stash literally everything in the working directory

  • git stash push -p

    Interactively select chunks to stash

  • git stash push --patch

    Pick specific hunks of changes to stash interactively

  • git stash push -- <file>

    Stash only changes made to a specific file

  • git stash pop

    Apply the most recent stash and remove it from the stash stack

  • git stash pop stash@{<n>}

    Apply and remove a specific stash index from the stack

  • git stash apply

    Apply the most recent stash without removing it from the stack

  • git stash apply stash@{<n>}

    Apply a specific stash without dropping it

  • git stash drop

    Discard the most recent stash from the stack entirely

  • git stash drop stash@{<n>}

    Discard a specific stash index permanently

  • git stash clear

    Delete all stashed entries simultaneously

  • git stash list

    List all currently saved stashes

  • git stash show

    Show the summary diff of the most recent stash

  • git stash show stash@{<n>}

    Show the summary diff for a specific stash index

  • git stash show -p

    Show the full patch diff of the most recent stash

  • git stash show -p stash@{<n>}

    Show the full patch diff for a specific stash index

  • git stash branch <branch>

    Create a new branch and apply the most recent stash to it

  • git stash branch <branch> stash@{<n>}

    Create a new branch and apply a specific stash to it

  • git rm <file>

    Remove a file from the working tree and stage the deletion

  • git rm -r <directory>

    Recursively remove a directory and stage the deletions

  • git rm --cached <file>

    Stop tracking a file but keep it in the working directory

  • git rm --cached -r <directory>

    Stop tracking a directory but leave the files locally

  • git rm -f <file>

    Forcefully remove a file from tracking and the working tree

  • git rm --force <file>

    Force delete a file ignoring local modifications

  • git rm -n <file>

    Dry run: test file removal without actually deleting it

  • git rm --dry-run <file>

    Simulate removing a file

  • git rm -q <file>

    Remove a file quietly without output

  • git commit --no-verify

    Commit changes bypassing Git hooks

Branching & Merging

  • git branch

    List all local branches

  • git branch <name>

    Create a new branch at the current commit but stay on current branch

  • git branch -a

    List all local and remote-tracking branches

  • git branch --all

    Display every branch known to the repository locally and remotely

  • git branch -r

    List only remote-tracking branches

  • git branch --remotes

    Display branches fetched from remotes

  • git branch -d <name>

    Safely delete a local branch if it has been merged

  • git branch --delete <name>

    Delete a branch, aborting if unmerged changes exist

  • git branch -D <name>

    Forcefully delete a local branch, losing unmerged changes

  • git branch -m <new-name>

    Rename the current branch

  • git branch -m <old-name> <new-name>

    Rename a specific branch

  • git branch --move <old-name> <new-name>

    Rename a branch locally

  • git branch -c <new-name>

    Copy the current branch to a new branch name

  • git branch --copy <new-name>

    Duplicate a branch

  • git branch -v

    List branches along with their latest commit hashes and subjects

  • git branch --verbose

    Show more info for each branch in the list

  • git branch -vv

    List branches with commit hashes, subjects, and remote tracking status

  • git branch --merged

    List branches that have been merged into the current branch

  • git branch --no-merged

    List branches containing unmerged work

  • git branch --contains <commit>

    List only branches that contain a specific commit

  • git branch -u <upstream>

    Set the upstream tracking branch for the current branch

  • git branch --set-upstream-to=<upstream>

    Link current branch to a remote upstream branch

  • git branch --unset-upstream

    Remove the upstream tracking link for the current branch

  • git branch -f <name> <commit>

    Forcefully reset an existing branch pointer to a specific commit

  • git branch --list

    Explicitly list branches (default behavior of git branch)

  • git branch --list "<pattern>"

    List branches matching a specific glob pattern

  • git checkout <branch>

    Switch the working directory to the specified branch

  • git checkout -b <new-branch>

    Create a new branch and immediately switch to it

  • git checkout -B <new-branch>

    Create a new branch or forcefully reset it if it exists, then switch

  • git checkout -b <new-branch> <start-point>

    Create a new branch starting at a specific commit and switch to it

  • git checkout --track <remote>/<branch>

    Create a local branch tracking a remote branch and switch to it

  • git checkout -t <remote>/<branch>

    Shorthand to checkout and track a remote branch locally

  • git checkout -- <file>

    Discard unstaged changes to a specific file, restoring from index

  • git checkout HEAD -- <file>

    Discard all local changes to a file, restoring it from HEAD

  • git checkout <commit> -- <file>

    Restore a specific file to its state in an older commit

  • git checkout -

    Switch back to the previous branch you were on

  • git checkout --orphan <new-branch>

    Create a new branch with no commit history

  • git checkout --detach

    Checkout HEAD directly, leaving branch context (detached HEAD)

  • git checkout <commit>

    Checkout a specific commit, resulting in a detached HEAD

  • git checkout <tag>

    Checkout a specific tag, resulting in a detached HEAD

  • git switch <branch>

    Switch working directory to an existing branch

  • git switch -c <new-branch>

    Create a new branch and switch to it (modern alternative to checkout -b)

  • git switch -C <new-branch>

    Force create or reset a branch and switch to it

  • git switch -c <new-branch> <start-point>

    Create a new branch from a start point and switch

  • git switch --track <remote>/<branch>

    Switch to a new local branch tracking a remote one

  • git switch --detach <commit>

    Switch to a commit in detached HEAD mode

  • git switch --orphan <new-branch>

    Switch to a new, history-less orphan branch

  • git switch -

    Switch to the previously checked out branch

  • git switch --guess

    Guess remote branch to track if local branch doesn't exist

  • git merge <branch>

    Merge the specified branch into the current active branch

  • git merge --no-ff <branch>

    Force a merge commit even if a fast-forward is possible

  • git merge --ff-only <branch>

    Merge only if a fast-forward is possible, otherwise abort

  • git merge --squash <branch>

    Stage the incoming branch's changes as a single commit, without merging history

  • git merge --abort

    Cancel an active merge process and restore the pre-merge state

  • git merge --continue

    Resume the merge process after resolving conflicts

  • git merge -m "<message>" <branch>

    Merge a branch and specify the merge commit message

  • git merge --strategy=<strategy> <branch>

    Use a specific merge strategy (e.g., recursive, octopus)

  • git merge -X <option> <branch>

    Pass strategy-specific options (e.g., -X theirs) during merge

  • git merge --allow-unrelated-histories <branch>

    Merge a branch that does not share a common ancestor

  • git merge --no-commit <branch>

    Perform the merge but stop before creating the final commit

  • git merge --stat <branch>

    Show a diffstat at the end of the merge process

  • git merge --no-stat <branch>

    Suppress the diffstat output at the end of a merge

  • git merge --log <branch>

    Populate the merge commit message with shortlogs from merged commits

  • git merge --no-ff -m "<message>" <branch>

    Force a merge commit with a custom message

  • git rebase <branch>

    Reapply current branch's commits on top of another branch

  • git rebase -i HEAD~<n>

    Open an interactive rebase editor for the last <n> commits

  • git rebase -i <commit>

    Start an interactive rebase beginning from a specific commit

  • git rebase --onto <newbase> <oldbase> <branch>

    Transplant a range of commits from oldbase to newbase

  • git rebase --abort

    Cancel an in-progress rebase and revert to original state

  • git rebase --continue

    Resume rebasing after resolving conflicts

  • git rebase --skip

    Skip the current patch that is causing a conflict during rebase

  • git rebase --autosquash

    Automatically squash commits marked with 'fixup!' or 'squash!'

  • git rebase --autostash

    Automatically stash and pop uncommitted changes around the rebase

  • git rebase -x <command>

    Execute a shell command after applying each commit during rebase

  • git rebase --exec <command>

    Run a test/command at every step of the rebase

  • git rebase --rebase-merges

    Attempt to preserve merge commits during the rebase process

  • git rebase --preserve-merges

    Deprecated: Re-create merge commits during rebase

  • git rebase -i --autosquash HEAD~<n>

    Interactively rebase and auto-process fixup commits

  • git rebase --onto <newbase> <oldbase>

    Rebase the current branch onto a new base excluding old base history

  • git cherry-pick <commit>

    Copy a specific commit from another branch to the current branch

  • git cherry-pick <commit1> <commit2>

    Cherry-pick two specific disconnected commits

  • git cherry-pick <commit1>..<commit2>

    Cherry-pick a continuous range of commits

  • git cherry-pick -x <commit>

    Cherry-pick and append a 'cherry picked from' note to the message

  • git cherry-pick -n <commit>

    Apply the commit's changes to the working tree without committing

  • git cherry-pick --no-commit <commit>

    Stage the cherry-picked changes but do not create a commit

  • git cherry-pick --edit <commit>

    Cherry-pick and open an editor to edit the commit message

  • git cherry-pick -e <commit>

    Allow editing the commit message before completing cherry-pick

  • git cherry-pick --abort

    Cancel an in-progress cherry-pick sequence

  • git cherry-pick --continue

    Resume a cherry-pick sequence after resolving conflicts

  • git cherry-pick --skip

    Skip the current conflicting commit in a cherry-pick sequence

  • git cherry-pick -s <commit>

    Add a Signed-off-by trailer to the cherry-picked commit

  • git cherry-pick --signoff <commit>

    Sign off on the cherry-picked commit

  • git cherry-pick --strategy=<strategy> <commit>

    Use a specific merge strategy when cherry-picking

Remote

  • git push

    Push local commits to the default tracked remote branch

  • git push <remote> <branch>

    Push a specific local branch to a specific remote

  • git push origin main

    Push the local main branch to the origin remote

  • git push origin HEAD

    Push the current branch to a branch of the same name on origin

  • git push -u <remote> <branch>

    Push and set the remote branch as the default upstream tracking branch

  • git push --set-upstream <remote> <branch>

    Explicitly link local branch to remote upon pushing

  • git push -f

    Force push changes, potentially overwriting remote history

  • git push --force

    Forcefully overwrite the remote branch with local history

  • git push --force-with-lease

    Force push safely, aborting if remote has unseen changes

  • git push --force-with-lease=<refname>:<expect>

    Force push requiring the remote ref to hold a specific expected value

  • git push --all

    Push all local branches to the remote

  • git push --follow-tags

    Push commits and automatically push any annotated tags attached to them

  • git push --no-verify

    Push changes bypassing the pre-push git hook

  • git push --dry-run

    Simulate a push to see what would be updated without transferring data

  • git push -d <remote> <branch>

    Delete a branch on the remote repository

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

    Explicitly delete a remote branch

  • git push <remote> :<branch>

    Push an empty ref to a remote branch, effectively deleting it

  • git push <remote> <local-branch>:<remote-branch>

    Push a local branch to a remote branch with a different name

  • git push -u origin main --force-with-lease

    Safely force push main and set upstream tracking

  • git push origin --delete <branch>

    Delete a specific branch on the origin remote

  • git push -u origin HEAD

    Push current branch to origin and link them

  • git pull

    Fetch changes from remote and merge them into the current branch

  • git pull <remote> <branch>

    Pull from a specific remote and branch

  • git pull --rebase

    Fetch changes and rebase local commits on top of the remote changes

  • git pull --no-rebase

    Fetch and forcefully create a merge commit instead of rebasing

  • git pull --ff-only

    Abort the pull if a fast-forward merge is not possible

  • git pull --no-ff

    Create a merge commit even if fast-forward is possible

  • git pull --squash

    Fetch and squash remote changes into the working tree without committing

  • git pull --all

    Fetch all remotes and merge tracked branch

  • git pull --depth <depth>

    Pull changes while limiting the historical depth of the fetch

  • git pull --autostash

    Automatically stash and pop changes to allow pulling cleanly

  • git pull --no-commit

    Pull and merge changes, but do not auto-commit the result

  • git pull origin main

    Pull changes specifically from the origin main branch

  • git pull --rebase origin main

    Rebase local changes on top of origin's main branch

  • git fetch

    Download new data from the default remote without merging

  • git fetch <remote>

    Download new data from a specific remote repository

  • git fetch --all

    Download new data from all configured remote repositories

  • git fetch --prune

    Fetch data and remove local refs to remote branches that were deleted

  • git fetch -p

    Shorthand for fetching and pruning stale remote-tracking branches

  • git fetch --tags

    Fetch all tags from the remote repository

  • git fetch --no-tags

    Fetch branch data without downloading any tags

  • git fetch --depth <depth>

    Fetch with a shallow history limit

  • git fetch --unshallow

    Convert a shallow repository to a complete repository by fetching all history

  • git fetch --dry-run

    Show what would be fetched without actually downloading anything

  • git fetch <remote> <branch>

    Fetch a specific branch from a remote

  • git fetch --all --prune

    Fetch from all remotes and clean up deleted branches

  • git fetch origin

    Download data specifically from the origin remote

  • git fetch origin main

    Download data just for the main branch on origin

  • git remote

    List the short names of configured remote repositories

  • git remote -v

    List remote repositories along with their fetch and push URLs

  • git remote --verbose

    Display detailed remote repository information

  • git remote add <name> <url>

    Add a new remote repository connection

  • git remote add origin <url>

    Add a new remote specifically named 'origin'

  • git remote remove <name>

    Delete a remote repository connection

  • git remote rm <name>

    Shorthand to remove a remote connection

  • git remote rename <old> <new>

    Rename an existing remote connection

  • git remote show <name>

    Show detailed tracking and branch info for a specific remote

  • git remote show origin

    Display tracking info for the origin remote

  • git remote set-url <name> <url>

    Change the URL of an existing remote

  • git remote set-url origin <url>

    Update the URL for the origin remote

  • git remote get-url <name>

    Print the current URL of a specific remote

  • git remote prune <name>

    Delete stale remote-tracking branches for a specific remote

  • git remote update

    Fetch updates from all remotes (similar to fetch --all)

  • git remote set-url --add <name> <url>

    Add a secondary push URL to a remote

  • git remote set-url --delete <name> <url>

    Remove a specific secondary URL from a remote

  • git push origin <tag>

    Push a specific local tag to the origin remote

  • git push origin --delete <tag>

    Delete a specific tag on the remote repository

  • git push origin refs/notes/commits

    Push git notes to the origin remote

  • git fetch origin refs/notes/commits:refs/notes/commits

    Fetch git notes from the origin remote

Inspection & History

  • git log

    Show the commit history for the current branch

  • git log --oneline

    Show commit history condensed to one line per commit

  • git log --graph

    Display an ASCII graph of the branch and merge history

  • git log --all

    Show the commit history for all branches and refs

  • git log --decorate

    Show branch names and tags pointing to commits in the log

  • git log --oneline --graph --all --decorate

    Show a colorful, condensed, graphical view of all repo history

  • git log -n <number>

    Limit the log output to a specific number of commits

  • git log -<number>

    Shorthand to limit the log output to <number> commits

  • git log --author="<name>"

    Filter the commit log by a specific author's name

  • git log --since="<date>"

    Show commits more recent than a specific date

  • git log --until="<date>"

    Show commits older than a specific date

  • git log --grep="<pattern>"

    Filter commits by a specific keyword in the commit message

  • git log -p

    Show the full patch/diff for each commit in the history

  • git log --patch

    Display the inline diffs introduced by every commit

  • git log --stat

    Show file additions and deletions statistics for each commit

  • git log --shortstat

    Show only the summary line of changes for each commit

  • git log --name-only

    List only the names of the files changed in each commit

  • git log --name-status

    List changed files alongside their modification status (A/M/D)

  • git log --follow <file>

    Show the history of a file, tracking past renames

  • git log -- <file>

    Show only the commits that modified a specific file

  • git log --merges

    Show only merge commits in the log output

  • git log --no-merges

    Exclude all merge commits from the log output

  • git log --first-parent

    Follow only the first parent of merge commits, simplifying history

  • git log --pretty=format:"<format>"

    Customize the visual output format of the commit log

  • git log --format="<format>"

    Shorthand to set a custom string format for commit logs

  • git log --abbrev-commit

    Show shortened SHA-1 hash strings in the log

  • git log --relative-date

    Display dates relative to now (e.g., '2 hours ago')

  • git log <branch>

    Show the commit history for a specific branch

  • git log <branch1>..<branch2>

    Show commits on branch2 that are not on branch1

  • git log --oneline --graph --all

    Show a condensed graphical history of all branches

  • git log --oneline -n 10

    Show the last 10 commits concisely

  • git log --since="2 weeks ago"

    Show history strictly from the last two weeks

  • git show

    Show the patch diff and message of the most recent commit

  • git show <commit>

    Show the details and diff of a specific commit

  • git show HEAD

    Show details for the current HEAD commit

  • git show HEAD~<n>

    Show details for the <n>th commit prior to HEAD

  • git show <tag>

    Display information about a specific annotated tag

  • git show <branch>

    Show the latest commit on a specific branch

  • git show <commit>:<file>

    Output the raw contents of a file as it existed in a specific commit

  • git show --stat <commit>

    Show only the file statistics for a specific commit

  • git show --name-only <commit>

    List the files altered in a specific commit

  • git show --oneline <commit>

    Show a condensed summary of a specific commit

  • git show --format="<format>" <commit>

    Display a commit using a customized text format

  • git blame <file>

    Annotate each line of a file with its last modifying commit and author

  • git blame -L <start>,<end> <file>

    Annotate only a specific line range within a file

  • git blame -L <start>,+<n> <file>

    Annotate starting at a line and extending <n> lines down

  • git blame -w <file>

    Ignore whitespace-only changes when determining line authorship

  • git blame -C <file>

    Detect lines moved or copied from other files in the same commit

  • git blame -M <file>

    Detect lines moved or copied within the same file

  • git blame --since=<date> <file>

    Annotate lines modified only after a specific date

  • git blame --ignore-rev <commit> <file>

    Ignore a specific formatting commit when assigning blame

  • git blame -e <file>

    Show the author's email address instead of their username

  • git blame -n <file>

    Show the original line number instead of the current one

  • git reflog

    Show a log of all recent local HEAD movements and operations

  • git reflog show

    Display the standard reference log for HEAD

  • git reflog show <branch>

    Show the reference log specifically for a local branch

  • git reflog show HEAD

    Explicitly view the HEAD reference log

  • git reflog expire

    Prune old entries from the reflog

  • git reflog expire --expire=<time>

    Prune reflog entries older than a specified time

  • git reflog expire --all

    Prune old entries across all reference logs

  • git reflog delete <ref>

    Delete a specific entry from the reflog

  • git reflog --oneline

    Display the reflog in a concise one-line format

  • git shortlog

    Group commit subjects by author name

  • git shortlog -s

    Provide a clean count of total commits per author

  • git shortlog -n

    Sort the shortlog output by number of commits instead of alphabetically

  • git shortlog -sn

    Show a ranked tally of commit counts per author

  • git shortlog -e

    Include the author's email address in the output

  • git shortlog --email

    Show emails alongside author names in the summary

  • git shortlog -sne

    Show a sorted tally of commits with author emails included

  • git shortlog --since=<date>

    Summarize commits made strictly after a specific date

  • git shortlog <commit1>..<commit2>

    Summarize authors and commits within a specific revision range

Undoing Changes

  • git restore <file>

    Discard unstaged local changes in a file

  • git restore .

    Discard all unstaged changes in the current directory

  • git restore --staged <file>

    Unstage a file, keeping the changes in the working directory

  • git restore --staged .

    Unstage all files in the current directory

  • git restore --source=<commit> <file>

    Restore a file's state to match a specific older commit

  • git restore --worktree <file>

    Explicitly restore a file in the working tree

  • git restore -s <commit> <file>

    Shorthand to pull a file version from a specific commit

  • git reset

    Unstage all files while preserving their changes in the working directory

  • git reset <file>

    Remove a specific file from the staging area

  • git reset HEAD <file>

    Unstage a file, keeping local modifications intact

  • git reset --soft HEAD~1

    Undo the last commit but keep changes staged and in the working directory

  • git reset --mixed HEAD~1

    Undo the last commit and unstage changes, keeping them in the working tree

  • git reset --hard HEAD~1

    Permanently undo the last commit and destroy all local changes

  • git reset --soft <commit>

    Move HEAD to a commit, leaving index and working tree untouched

  • git reset --mixed <commit>

    Move HEAD to a commit and unstage, but preserve working tree

  • git reset --hard <commit>

    Force reset HEAD to a commit and forcefully overwrite working tree

  • git reset HEAD

    Unstage all files currently added to the index

  • git reset HEAD~<n>

    Undo the last <n> commits, leaving changes unstaged

  • git reset --hard HEAD

    Destroy all unstaged and staged changes, resetting to the last commit

  • git reset --keep <commit>

    Reset HEAD but keep local modifications that don't conflict

  • git reset --merge <commit>

    Reset HEAD and abort a conflicted merge attempt safely

  • git revert <commit>

    Generate a new commit that applies the inverse of a specific commit

  • git revert HEAD

    Create a new commit undoing the changes of the last commit

  • git revert HEAD~<n>

    Revert the changes introduced by the <n>th previous commit

  • git revert --no-commit <commit>

    Apply the inverse of a commit to the working tree without committing

  • git revert -n <commit>

    Stage reverted changes but wait for manual commit

  • git revert --no-edit <commit>

    Revert a commit and automatically use the default revert message

  • git revert --mainline <n> <commit>

    Revert a merge commit by specifying which parent mainline to keep

  • git revert -m <n> <commit>

    Shorthand for reverting a merge commit along a specific parent

  • git revert <commit>..<commit>

    Revert a continuous sequence of commits

  • git revert --abort

    Cancel an active revert process and return to the previous state

  • git revert --continue

    Resume the revert process after resolving file conflicts

  • git clean -f

    Forcefully remove all untracked files from the working directory

  • git clean -fd

    Remove all untracked files and untracked directories

  • git clean -fx

    Remove untracked files, including those ignored by .gitignore

  • git clean -fX

    Remove only files that are explicitly ignored by .gitignore

  • git clean -fdx

    Nuke working tree: remove all untracked/ignored files and directories

  • git clean -n

    Perform a dry run to see which untracked files would be deleted

  • git clean --dry-run

    Preview untracked file deletion safely

  • git clean -i

    Interactively choose which untracked files to delete

  • git clean -q

    Remove untracked files quietly without console output

  • git clean -e <pattern>

    Clean untracked files but explicitly exempt files matching a pattern

  • git clean -f -- <path>

    Remove untracked files strictly within a specific path/directory

Tags

  • git push --tags

    Push all local tags to the remote repository

  • git tag

    List all tags in the local repository

  • git tag <name>

    Create a lightweight tag at the current HEAD commit

  • git tag <name> <commit>

    Create a lightweight tag pointing to a specific older commit

  • git tag -a <name> -m "<message>"

    Create an annotated tag with a specific message

  • git tag -a <name> <commit> -m "<message>"

    Create an annotated tag at a specific commit

  • git tag -s <name> -m "<message>"

    Create a cryptographically GPG-signed annotated tag

  • git tag -d <name>

    Delete a specific tag from the local repository

  • git tag --delete <name>

    Explicitly delete a local tag

  • git tag -l

    List local tags (same as standard git tag)

  • git tag --list

    List local tags explicitly

  • git tag -l "<pattern>"

    List tags matching a specific glob wildcard pattern

  • git tag --contains <commit>

    List only the tags that include a specific commit in their history

  • git tag --sort=version:refname

    List tags sorted intelligently by semantic version numbers

  • git tag -f <name> <commit>

    Forcefully overwrite an existing tag to point to a new commit

  • git push origin --tags

    Push all local tags explicitly to the origin remote

Submodules

  • git submodule add <url>

    Add a new external repository as a submodule

  • git submodule add <url> <path>

    Add a submodule and place it in a specific local path

  • git submodule init

    Initialize submodules recorded in the index

  • git submodule update

    Update the registered submodules to match what the superproject expects

  • git submodule update --init

    Initialize and update submodules in a single step

  • git submodule update --init --recursive

    Initialize and update submodules, including nested submodules

  • git submodule update --remote

    Update submodules to the latest commit on their remote tracking branch

  • git submodule update --remote --merge

    Fetch remote submodule changes and merge them into the local submodule

  • git submodule update --remote --rebase

    Fetch remote submodule changes and rebase local changes on top

  • git submodule status

    Show the status, commit hash, and path of all submodules

  • git submodule foreach <command>

    Execute a specific shell command inside every submodule

  • git submodule foreach --recursive <command>

    Execute a command inside all submodules and nested submodules

  • git submodule deinit <path>

    Unregister a submodule, removing its local configuration

  • git submodule deinit --all

    Unregister all submodules from the local repository

  • git submodule sync

    Synchronize submodule URLs from .gitmodules to the local config

  • git submodule sync --recursive

    Synchronize submodule URLs for all nested submodules

Worktree

  • git worktree add <path>

    Create a new working tree linked to the repo in a separate directory

  • git worktree add <path> <branch>

    Create a new working tree and checkout a specific branch into it

  • git worktree add -b <new-branch> <path>

    Create a new branch and checkout into a new separate working tree

  • git worktree add -b <new-branch> <path> <commit>

    Create a new branch from a commit and open in a new working tree

  • git worktree add --detach <path>

    Create a new working tree checked out in a detached HEAD state

  • git worktree list

    List all active worktrees linked to the current repository

  • git worktree list --porcelain

    List worktrees in a machine-readable format

  • git worktree prune

    Clean up administrative files for deleted or moved worktrees

  • git worktree remove <path>

    Safely delete a working tree and its associated data

  • git worktree remove --force <path>

    Force delete a working tree, ignoring uncommitted changes

  • git worktree lock <path>

    Lock a worktree to prevent it from being automatically pruned

  • git worktree unlock <path>

    Unlock a previously locked worktree

  • git worktree move <path> <new-path>

    Move an existing working tree to a new directory path

Bisect

  • git bisect start

    Initiate a binary search session to track down a bug

  • git bisect good <commit>

    Mark a specific older commit as 'good' (bug-free)

  • git bisect bad <commit>

    Mark a specific newer commit as 'bad' (containing the bug)

  • git bisect good

    Mark the currently checked-out commit as 'good'

  • git bisect bad

    Mark the currently checked-out commit as 'bad'

  • git bisect skip

    Skip the current commit if it cannot be tested (e.g., won't compile)

  • git bisect reset

    End the bisect session and return to the original branch

  • git bisect run <script>

    Automate bisecting using a script that returns 0 for good, non-zero for bad

  • git bisect log

    View the history of good/bad markings in the current bisect session

  • git bisect visualize

    Show the remaining suspect commits in a graphical interface or log

  • git bisect start <bad> <good>

    Start bisect and immediately provide the known bad and good bounds

Sparse Checkout

  • git sparse-checkout init

    Enable sparse checkout to only load parts of the repository

  • git sparse-checkout init --cone

    Enable cone-mode sparse checkout for faster performance with directories

  • git sparse-checkout set <pattern>

    Define the exact patterns or directories to include in the working tree

  • git sparse-checkout add <pattern>

    Add additional directories or patterns to the existing sparse checkout

  • git sparse-checkout list

    List the current patterns determining the sparse checkout

  • git sparse-checkout disable

    Turn off sparse checkout and repopulate the entire working tree

  • git sparse-checkout reapply

    Reapply the sparse checkout rules to the current working tree

Notes

  • git notes add -m "<message>" <commit>

    Attach a textual note to a specific commit without altering its hash

  • git notes show <commit>

    View the note attached to a specific commit

  • git notes edit <commit>

    Modify an existing note on a specific commit interactively

  • git notes remove <commit>

    Delete the note attached to a specific commit

  • git notes list

    List all notes currently existing in the repository

  • git notes append -m "<message>" <commit>

    Add new text to an existing note on a commit