Git Advanced Command Cheatsheet
This cheatsheet is designed for developers who already know basic Git. It covers interactive rebase, binary search, reflog, cherry-pick, submodule management, and worktrees. Mastering these commands will significantly boost your daily productivity.
Updated: 2026-07-17·37 commands
Overview
This cheatsheet covers advanced Git operations beyond the basic workflow. Master these commands to handle complex version control scenarios with confidence.
Quick Start
``bash
git rebase -i HEAD~3 # Interactive rebase last 3 commits
git reflog # View reference log
git bisect start # Start binary search
``
Refer to the command table below for detailed usage.
Rebase(13)
| Command | Level | ||
|---|---|---|---|
git rebase -i [base]Interactive rebase that allows editing, squashing, deleting, and reordering commits | Intermediate | git rebase -i HEAD~5 | |
git rebase --onto newbase oldbase [branch]Rebase commits from branch that follow oldbase onto newbase, for precise commit transplanting | Expert | git rebase --onto master feature~3 feature | |
git rebase --abortAbort the current rebase with conflicts and restore the original state | Intermediate | git rebase --abort | |
git rebase --continueContinue the rebase operation after resolving conflicts | Intermediate | git rebase --continue | |
git rebase --skipSkip the current commit causing conflicts and continue rebasing | Intermediate | git rebase --skip | |
git stash -u [message]Stash working directory changes including untracked files (--include-untracked) | Intermediate | git stash -u WIP-refactoring | |
git stash --keep-index [message]Stash working directory changes but keep staged changes intact (preserve index) | Intermediate | git stash --keep-index "temp save unstaged" | |
git stash branch branchname [stash]Create a new branch from a stash and apply the stash, useful when stash pop fails due to conflicts | Expert | git stash branch fix-feature stash@{1} | |
git clean -fdForce remove all untracked files and directories from the working tree | Intermediate | git clean -fd | |
git grep [pattern] [revision]Search the Git repository for lines matching a pattern, supports searching in specific revisions | Intermediate | git grep "TODO" v2.0.0 | |
git shortlog [options]Summarize commit logs by author, commonly used for generating changelogs | Intermediate | git shortlog -sn --since="2026-01-01" | |
git describe [ref]Generate a human-readable name for a commit based on the nearest tag, format tag-N-gHASH | Intermediate | git describe --tags --abbrev=4 HEAD | |
git rebase --abortAbort an in-progress rebase and return to the pre-rebase state | Basic | git rebase --abort |
Bisect(5)
| Command | Level | ||
|---|---|---|---|
git bisect start [bad [good...]]Start a bisect session, marking known good and bad commit ranges | Expert | git bisect start HEAD v1.0.0 | |
git bisect bad [rev]Mark the current or specified revision as bad (contains the bug) | Expert | git bisect bad | |
git bisect good [rev]Mark the current or specified revision as good (does not contain the bug) | Expert | git bisect good v1.0.0 | |
git bisect resetEnd the bisect session and restore HEAD to the original position | Expert | git bisect reset | |
git bisect logShow the current bisect session log, useful for replaying or debugging the process | Expert | git bisect log |
Reflog(3)
| Command | Level | ||
|---|---|---|---|
git reflog show [ref]Show the operation history of a reference (default HEAD), useful for recovering lost commits | Intermediate | git reflog show --date=iso HEAD | |
git reflog delete [entry]Delete a specific entry from the reflog | Expert | git reflog delete HEAD@{2} | |
git reflog expire [options]Expire old reflog entries and clean up, usually run automatically by git gc | Expert | git reflog expire --expire=30.days --all |
Cherry-pick(5)
| Command | Level | ||
|---|---|---|---|
git cherry-pick [commit]Apply the changes from a specific commit to the current branch, creating a new commit | Intermediate | git cherry-pick a1b2c3d | |
git cherry-pick -n [commit]Apply changes from a commit to working tree and index without auto-committing | Intermediate | git cherry-pick -n a1b2c3d | |
git cherry-pick -x [commit]Apply a commit and append a source reference in the commit message (cherry picked from ...) | Intermediate | git cherry-pick -x a1b2c3d | |
git cherry-pick --signoff [commit]Apply a commit and add a Signed-off-by trailer line to the commit message | Intermediate | git cherry-pick --signoff a1b2c3d | |
git cherry-pick <commit>Apply changes from a specific commit to the current branch | Basic | git cherry-pick abc123 |
Submodules(6)
| Command | Level | ||
|---|---|---|---|
git submodule add [repository] [path]Add a new submodule to the repository | Intermediate | git submodule add https://github.com/example/lib lib | |
git submodule update [--init] [--recursive]Update submodules to their registered commit, --init initializes uninitialized ones | Intermediate | git submodule update --init --recursive | |
git submodule initInitialize submodule configurations based on the .gitmodules file | Intermediate | git submodule init | |
git submodule foreach [command]Execute a command in each submodule | Expert | git submodule foreach git pull origin main | |
git submodule status [--recursive]Show the current status of submodules, including commit hash and initialization state | Intermediate | git submodule status --recursive | |
git submodule deinit [path]Unregister a submodule, removing its working tree while keeping .gitmodules config | Expert | git submodule deinit -f lib |
Worktrees(5)
| Command | Level | ||
|---|---|---|---|
git worktree add [path] [branch]Check out a new working tree in a new directory, attached to the specified branch | Intermediate | git worktree add ../hotfix hotfix-branch | |
git worktree listList all worktrees associated with this repo, their paths, and branch info | Intermediate | git worktree list | |
git worktree prune [options]Prune working tree records for worktrees that have been removed or are unreachable | Expert | git worktree prune --expire 30.days | |
git worktree remove [path]Remove a working tree at the specified path while keeping the repository data | Intermediate | git worktree remove ../hotfix | |
git worktree lock [path]Lock a working tree to prevent it from being pruned or removed | Intermediate | git worktree lock ../hotfix --reason "active bugfix" |
FAQ
This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-17.