Skip to main content

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)

CommandLevel
git rebase -i [base]
Interactive rebase that allows editing, squashing, deleting, and reordering commits
Intermediate
git rebase --onto newbase oldbase [branch]
Rebase commits from branch that follow oldbase onto newbase, for precise commit transplanting
Expert
git rebase --abort
Abort the current rebase with conflicts and restore the original state
Intermediate
git rebase --continue
Continue the rebase operation after resolving conflicts
Intermediate
git rebase --skip
Skip the current commit causing conflicts and continue rebasing
Intermediate
git stash -u [message]
Stash working directory changes including untracked files (--include-untracked)
Intermediate
git stash --keep-index [message]
Stash working directory changes but keep staged changes intact (preserve index)
Intermediate
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 clean -fd
Force remove all untracked files and directories from the working tree
Intermediate
git grep [pattern] [revision]
Search the Git repository for lines matching a pattern, supports searching in specific revisions
Intermediate
git shortlog [options]
Summarize commit logs by author, commonly used for generating changelogs
Intermediate
git describe [ref]
Generate a human-readable name for a commit based on the nearest tag, format tag-N-gHASH
Intermediate
git rebase --abort
Abort an in-progress rebase and return to the pre-rebase state
Basic

Bisect(5)

CommandLevel
git bisect start [bad [good...]]
Start a bisect session, marking known good and bad commit ranges
Expert
git bisect bad [rev]
Mark the current or specified revision as bad (contains the bug)
Expert
git bisect good [rev]
Mark the current or specified revision as good (does not contain the bug)
Expert
git bisect reset
End the bisect session and restore HEAD to the original position
Expert
git bisect log
Show the current bisect session log, useful for replaying or debugging the process
Expert

Reflog(3)

CommandLevel
git reflog show [ref]
Show the operation history of a reference (default HEAD), useful for recovering lost commits
Intermediate
git reflog delete [entry]
Delete a specific entry from the reflog
Expert
git reflog expire [options]
Expire old reflog entries and clean up, usually run automatically by git gc
Expert

Cherry-pick(5)

CommandLevel
git cherry-pick [commit]
Apply the changes from a specific commit to the current branch, creating a new commit
Intermediate
git cherry-pick -n [commit]
Apply changes from a commit to working tree and index without auto-committing
Intermediate
git cherry-pick -x [commit]
Apply a commit and append a source reference in the commit message (cherry picked from ...)
Intermediate
git cherry-pick --signoff [commit]
Apply a commit and add a Signed-off-by trailer line to the commit message
Intermediate
git cherry-pick <commit>
Apply changes from a specific commit to the current branch
Basic

Submodules(6)

CommandLevel
git submodule add [repository] [path]
Add a new submodule to the repository
Intermediate
git submodule update [--init] [--recursive]
Update submodules to their registered commit, --init initializes uninitialized ones
Intermediate
git submodule init
Initialize submodule configurations based on the .gitmodules file
Intermediate
git submodule foreach [command]
Execute a command in each submodule
Expert
git submodule status [--recursive]
Show the current status of submodules, including commit hash and initialization state
Intermediate
git submodule deinit [path]
Unregister a submodule, removing its working tree while keeping .gitmodules config
Expert

Worktrees(5)

CommandLevel
git worktree add [path] [branch]
Check out a new working tree in a new directory, attached to the specified branch
Intermediate
git worktree list
List all worktrees associated with this repo, their paths, and branch info
Intermediate
git worktree prune [options]
Prune working tree records for worktrees that have been removed or are unreachable
Expert
git worktree remove [path]
Remove a working tree at the specified path while keeping the repository data
Intermediate
git worktree lock [path]
Lock a working tree to prevent it from being pruned or removed
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-17.