Git commands
Distributed version control system
Setup & Config
git initInitialize 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 --bareInitialize 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 --listList all Git configuration settings applied in the current scope
git config --global --listList global Git configuration settings for the current user
git config --local --listList configuration settings specific to the current repository
git config --system --listList 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 trueConfigure Git to rebase by default when pulling changes
git config --global push.default currentSet 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 --editOpen the local Git configuration file in the default editor
git config --global --editOpen 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 -AStage all changes, including deletions, across the entire working tree
git add --allStage everything: modifications, new files, and deletions
git add -pInteractively stage specific chunks (hunks) of changes
git add --patchInteractively choose which parts of files to stage
git add -uStage modifications and deletions, but ignore new untracked files
git add --updateUpdate the index just for files that are already tracked
git add -nDry run: show what files would be staged without actually staging them
git add --dry-runSimulate 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 -iOpen the interactive staging prompt menu
git add --interactiveStart an interactive session to manage the staging area
git add -eOpen the diff in an editor to manually edit what gets staged
git add --editManually edit the patch file before staging it
git add *.jsStage all files matching a specific extension (e.g., .js)
git add <dir>/Stage all modified and new files within a specific directory
git commitCreate 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 -aAutomatically 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 --amendCombine 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-editAdd staged changes to the previous commit without altering its message
git commit -m "<message>" --allow-emptyCreate 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 -vOpen editor with the diff of what is being committed visible
git commit --verboseShow the full unified diff in the commit message editor
git commit -qCommit quietly, suppressing standard summary output
git commit --quietCommit 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 statusShow the state of the working directory and staging area
git status -sShow status in a concise short format
git status --shortDisplay shortened status output
git status -bShow current branch tracking info alongside short status
git status --branchInclude branch tracking information in the output
git status -sbShow concise short status alongside branch info
git status --porcelainOutput machine-readable status meant for parsing by scripts
git status -uShow untracked files explicitly in the output
git status --untracked-files=allList untracked files and untracked directories contents individually
git status --ignoredShow status and also list ignored files
git status --ahead-behindCalculate and display how far ahead or behind the remote branch is
git diffShow unstaged changes in the working directory
git diff <file>Show unstaged changes for a specific file
git diff --stagedShow changes that are currently staged for the next commit
git diff --cachedAlias for --staged, showing changes ready to be committed
git diff HEADShow all changes (staged and unstaged) since the last commit
git diff HEAD~1Show 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 --statShow a summary of lines added/removed instead of the full diff
git diff --name-onlyOutput only the names of the files that changed
git diff --name-statusOutput filenames and their modification status (Added, Modified, etc.)
git diff --word-diffShow differences at the word level instead of line-by-line
git diff --colorForce colored output for diffs
git diff --no-colorDisable 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-changeIgnore changes in amount of whitespace
git diff -wCompletely ignore all whitespace when comparing lines
git diff --ignore-all-spaceIgnore 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-onlyList names of all files changed since the last commit
git diff --staged --statShow a summary of the changes staged for the next commit
git stashTemporarily save unstaged and staged changes in a stack
git stash pushExplicitly push current changes onto the stash stack
git stash push -m "<message>"Stash current changes with a specific descriptive message
git stash push -uStash tracked file changes along with untracked files
git stash push --include-untrackedInclude untracked files when stashing changes
git stash push -aStash all changes, including untracked and ignored files
git stash push --allStash literally everything in the working directory
git stash push -pInteractively select chunks to stash
git stash push --patchPick specific hunks of changes to stash interactively
git stash push -- <file>Stash only changes made to a specific file
git stash popApply 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 applyApply the most recent stash without removing it from the stack
git stash apply stash@{<n>}Apply a specific stash without dropping it
git stash dropDiscard the most recent stash from the stack entirely
git stash drop stash@{<n>}Discard a specific stash index permanently
git stash clearDelete all stashed entries simultaneously
git stash listList all currently saved stashes
git stash showShow 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 -pShow 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-verifyCommit changes bypassing Git hooks
Branching & Merging
git branchList all local branches
git branch <name>Create a new branch at the current commit but stay on current branch
git branch -aList all local and remote-tracking branches
git branch --allDisplay every branch known to the repository locally and remotely
git branch -rList only remote-tracking branches
git branch --remotesDisplay 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 -vList branches along with their latest commit hashes and subjects
git branch --verboseShow more info for each branch in the list
git branch -vvList branches with commit hashes, subjects, and remote tracking status
git branch --mergedList branches that have been merged into the current branch
git branch --no-mergedList 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-upstreamRemove 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 --listExplicitly 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 --detachCheckout 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 --guessGuess 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 --abortCancel an active merge process and restore the pre-merge state
git merge --continueResume 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 --abortCancel an in-progress rebase and revert to original state
git rebase --continueResume rebasing after resolving conflicts
git rebase --skipSkip the current patch that is causing a conflict during rebase
git rebase --autosquashAutomatically squash commits marked with 'fixup!' or 'squash!'
git rebase --autostashAutomatically 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-mergesAttempt to preserve merge commits during the rebase process
git rebase --preserve-mergesDeprecated: 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 --abortCancel an in-progress cherry-pick sequence
git cherry-pick --continueResume a cherry-pick sequence after resolving conflicts
git cherry-pick --skipSkip 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 pushPush local commits to the default tracked remote branch
git push <remote> <branch>Push a specific local branch to a specific remote
git push origin mainPush the local main branch to the origin remote
git push origin HEADPush 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 -fForce push changes, potentially overwriting remote history
git push --forceForcefully overwrite the remote branch with local history
git push --force-with-leaseForce 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 --allPush all local branches to the remote
git push --follow-tagsPush commits and automatically push any annotated tags attached to them
git push --no-verifyPush changes bypassing the pre-push git hook
git push --dry-runSimulate 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-leaseSafely force push main and set upstream tracking
git push origin --delete <branch>Delete a specific branch on the origin remote
git push -u origin HEADPush current branch to origin and link them
git pullFetch changes from remote and merge them into the current branch
git pull <remote> <branch>Pull from a specific remote and branch
git pull --rebaseFetch changes and rebase local commits on top of the remote changes
git pull --no-rebaseFetch and forcefully create a merge commit instead of rebasing
git pull --ff-onlyAbort the pull if a fast-forward merge is not possible
git pull --no-ffCreate a merge commit even if fast-forward is possible
git pull --squashFetch and squash remote changes into the working tree without committing
git pull --allFetch all remotes and merge tracked branch
git pull --depth <depth>Pull changes while limiting the historical depth of the fetch
git pull --autostashAutomatically stash and pop changes to allow pulling cleanly
git pull --no-commitPull and merge changes, but do not auto-commit the result
git pull origin mainPull changes specifically from the origin main branch
git pull --rebase origin mainRebase local changes on top of origin's main branch
git fetchDownload new data from the default remote without merging
git fetch <remote>Download new data from a specific remote repository
git fetch --allDownload new data from all configured remote repositories
git fetch --pruneFetch data and remove local refs to remote branches that were deleted
git fetch -pShorthand for fetching and pruning stale remote-tracking branches
git fetch --tagsFetch all tags from the remote repository
git fetch --no-tagsFetch branch data without downloading any tags
git fetch --depth <depth>Fetch with a shallow history limit
git fetch --unshallowConvert a shallow repository to a complete repository by fetching all history
git fetch --dry-runShow what would be fetched without actually downloading anything
git fetch <remote> <branch>Fetch a specific branch from a remote
git fetch --all --pruneFetch from all remotes and clean up deleted branches
git fetch originDownload data specifically from the origin remote
git fetch origin mainDownload data just for the main branch on origin
git remoteList the short names of configured remote repositories
git remote -vList remote repositories along with their fetch and push URLs
git remote --verboseDisplay 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 originDisplay 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 updateFetch 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/commitsPush git notes to the origin remote
git fetch origin refs/notes/commits:refs/notes/commitsFetch git notes from the origin remote
Inspection & History
git logShow the commit history for the current branch
git log --onelineShow commit history condensed to one line per commit
git log --graphDisplay an ASCII graph of the branch and merge history
git log --allShow the commit history for all branches and refs
git log --decorateShow branch names and tags pointing to commits in the log
git log --oneline --graph --all --decorateShow 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 -pShow the full patch/diff for each commit in the history
git log --patchDisplay the inline diffs introduced by every commit
git log --statShow file additions and deletions statistics for each commit
git log --shortstatShow only the summary line of changes for each commit
git log --name-onlyList only the names of the files changed in each commit
git log --name-statusList 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 --mergesShow only merge commits in the log output
git log --no-mergesExclude all merge commits from the log output
git log --first-parentFollow 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-commitShow shortened SHA-1 hash strings in the log
git log --relative-dateDisplay 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 --allShow a condensed graphical history of all branches
git log --oneline -n 10Show the last 10 commits concisely
git log --since="2 weeks ago"Show history strictly from the last two weeks
git showShow the patch diff and message of the most recent commit
git show <commit>Show the details and diff of a specific commit
git show HEADShow 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 reflogShow a log of all recent local HEAD movements and operations
git reflog showDisplay the standard reference log for HEAD
git reflog show <branch>Show the reference log specifically for a local branch
git reflog show HEADExplicitly view the HEAD reference log
git reflog expirePrune old entries from the reflog
git reflog expire --expire=<time>Prune reflog entries older than a specified time
git reflog expire --allPrune old entries across all reference logs
git reflog delete <ref>Delete a specific entry from the reflog
git reflog --onelineDisplay the reflog in a concise one-line format
git shortlogGroup commit subjects by author name
git shortlog -sProvide a clean count of total commits per author
git shortlog -nSort the shortlog output by number of commits instead of alphabetically
git shortlog -snShow a ranked tally of commit counts per author
git shortlog -eInclude the author's email address in the output
git shortlog --emailShow emails alongside author names in the summary
git shortlog -sneShow 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 resetUnstage 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~1Undo the last commit but keep changes staged and in the working directory
git reset --mixed HEAD~1Undo the last commit and unstage changes, keeping them in the working tree
git reset --hard HEAD~1Permanently 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 HEADUnstage all files currently added to the index
git reset HEAD~<n>Undo the last <n> commits, leaving changes unstaged
git reset --hard HEADDestroy 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 HEADCreate 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 --abortCancel an active revert process and return to the previous state
git revert --continueResume the revert process after resolving file conflicts
git clean -fForcefully remove all untracked files from the working directory
git clean -fdRemove all untracked files and untracked directories
git clean -fxRemove untracked files, including those ignored by .gitignore
git clean -fXRemove only files that are explicitly ignored by .gitignore
git clean -fdxNuke working tree: remove all untracked/ignored files and directories
git clean -nPerform a dry run to see which untracked files would be deleted
git clean --dry-runPreview untracked file deletion safely
git clean -iInteractively choose which untracked files to delete
git clean -qRemove 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 --tagsPush all local tags to the remote repository
git tagList 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 -lList local tags (same as standard git tag)
git tag --listList 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:refnameList 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 --tagsPush 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 initInitialize submodules recorded in the index
git submodule updateUpdate the registered submodules to match what the superproject expects
git submodule update --initInitialize and update submodules in a single step
git submodule update --init --recursiveInitialize and update submodules, including nested submodules
git submodule update --remoteUpdate submodules to the latest commit on their remote tracking branch
git submodule update --remote --mergeFetch remote submodule changes and merge them into the local submodule
git submodule update --remote --rebaseFetch remote submodule changes and rebase local changes on top
git submodule statusShow 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 --allUnregister all submodules from the local repository
git submodule syncSynchronize submodule URLs from .gitmodules to the local config
git submodule sync --recursiveSynchronize 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 listList all active worktrees linked to the current repository
git worktree list --porcelainList worktrees in a machine-readable format
git worktree pruneClean 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 startInitiate 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 goodMark the currently checked-out commit as 'good'
git bisect badMark the currently checked-out commit as 'bad'
git bisect skipSkip the current commit if it cannot be tested (e.g., won't compile)
git bisect resetEnd 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 logView the history of good/bad markings in the current bisect session
git bisect visualizeShow 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 initEnable sparse checkout to only load parts of the repository
git sparse-checkout init --coneEnable 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 listList the current patterns determining the sparse checkout
git sparse-checkout disableTurn off sparse checkout and repopulate the entire working tree
git sparse-checkout reapplyReapply 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 listList all notes currently existing in the repository
git notes append -m "<message>" <commit>Add new text to an existing note on a commit