Agent skill

Git Surgeon

by raine in raine/git-surgeon

Non-interactive hunk-level git staging, unstaging, discarding, undoing, fold, amend, squash, commit splitting, and commit reordering.

MITAuto-check passedDevelopment

Install Git Surgeon

skills CLI
$ npx skills add raine/git-surgeon --skill git-surgeon -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install raine/git-surgeon git-surgeon --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/raine/git-surgeon.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/git-surgeon .claude/skills/git-surgeon && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
git-surgeon
GitHub stars
171
Token cost
~2.3k tokens
SKILL.md length
738 words
Files
1
Skills in repo
1
Repo updated
First seen
Licence
MIT

At a glance

Non-interactive hunk-level git staging, unstaging, discarding, undoing, fold, amend, squash, commit splitting, and commit reordering.

  • Works in 5 steps: Run git-surgeon hunks to list hunks with… → Use git-surgeon show to inspect a hunk… → Stage and commit in one step:… → …
  • Selectively staging
  • SKILL.md covers Commands, Typical workflow, Committing to another branch and Picking the right folding…, plus 7 more sections
  • Calls git

What it does

Git Surgeon is an agent skill from raine/git-surgeon. Non-interactive hunk-level git staging, unstaging, discarding, undoing, fold, amend, squash, commit splitting, and commit reordering. Use when selectively staging, unstaging, discarding, reverting, squashing, splitting, or reordering individual diff hunks by ID instead of interactively.

Its SKILL.md is about 2.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Git workflow. It works with Git. The repository describes itself as: Git primitives for autonomous coding agents. The licence is MIT.

When your agent uses it

  • Selectively staging
  • Reordering individual diff hunks by ID instead of interactively

Example prompts

  • “/git-surgeon”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Run git-surgeon hunks to list hunks with their IDs
  2. Use git-surgeon show to inspect a hunk (lines are numbered)
  3. Stage and commit in one step: git-surgeon commit -m "message"
  4. Or stage separately: git-surgeon stage , then git commit
  5. To commit only part of a hunk, use inline ranges: git-surgeon commit :5-30 -m "message"

What it can do on your machine

Read from SKILL.md and the folder at commit 798e80e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • git

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Git Surgeon loads about 2.3k tokens when it runs. Until then it costs about 75 tokens; SKILL.md has 738 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~75
When it runs · the whole SKILL.md, loaded when a task matches
~2.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from raine/git-surgeon at commit 798e80e, republished under its MIT licence (© raine). 738 words, ~2,330 tokens.

Download SKILL.mdSave it as .claude/skills/git-surgeon/SKILL.md (or your agent's skills folder).
name
git-surgeon
description
Non-interactive hunk-level git staging, unstaging, discarding, undoing, fold, amend, squash, commit splitting, and commit reordering. Use when selectively staging, unstaging, discarding, reverting, squashing, splitting, or reordering individual diff hunks by ID instead of interactively.

git-surgeon

CLI for hunk-level git operations without interactive prompts. Useful for AI agents that need precise control over which changes to stage, unstage, discard, or undo.

Commands

bash
# List unstaged hunks (shows ID, file, +/- counts, preview)
git-surgeon hunks

# List staged hunks
git-surgeon hunks --staged

# Filter to one file
git-surgeon hunks --file=src/main.rs

# List hunks from a specific commit
git-surgeon hunks --commit <HEAD/sha>

# Show all hunks with line numbers (for small commits needing line-range splits)
git-surgeon hunks --commit <sha> --full

# Show blame info (which commit introduced each line)
git-surgeon hunks --blame
git-surgeon hunks --blame --staged
git-surgeon hunks --blame --commit <sha>

# Show full diff for a hunk (lines are numbered for use with --lines)
git-surgeon show <id>
git-surgeon show <id> --commit HEAD

# Stage specific hunks
git-surgeon stage <id1> <id2> ...

# Stage only part of a hunk by line range
git-surgeon stage <id> --lines 5-30

# Stage and commit hunks in one step
git-surgeon commit <id1> <id2> ... -m "message"

# With inline line ranges
git-surgeon commit <id>:1-11 <id2> -m "message"

# Commit hunks directly to another branch (no checkout needed)
git-surgeon commit-to <branch> <id1> <id2> ... -m "message"
git-surgeon commit-to main <id>:1-11 <id2> -m "message"

# Unstage specific hunks
git-surgeon unstage <id1> <id2> ...
git-surgeon unstage <id> --lines 5-30

# Discard working tree changes for specific hunks
git-surgeon discard <id1> <id2> ...
git-surgeon discard <id> --lines 5-30

# Fold existing commits into an earlier commit (default: HEAD into target)
git-surgeon fold <target>
git-surgeon fold <target> --from <commit>
git-surgeon fold <target> --from <commit1> <commit2> <commit3>

# Fold staged changes into an earlier commit
git-surgeon amend <commit>

# Change commit message
git-surgeon reword HEAD -m "new message"
git-surgeon reword <commit> -m "new message"
git-surgeon reword HEAD -m "subject" -m "body"

# Squash ALL commits from <commit> through HEAD into one
git-surgeon squash HEAD~1 -m "combined feature"
git-surgeon squash HEAD~2 -m "Add user auth" -m "Implements JWT-based authentication."
git-surgeon squash <commit> -m "feature complete"
git-surgeon squash HEAD~3 --force -m "squash with merges"
git-surgeon squash HEAD~1 --no-preserve-author -m "use current author"

# Undo specific hunks from a commit (reverse-apply to working tree)
git-surgeon undo <id1> <id2> ... --from <commit>
git-surgeon undo <id> --from <commit> --lines 2-10

# Undo all changes to specific files from a commit
git-surgeon undo-file <file1> <file2> ... --from <commit>

# Split a commit into multiple commits by hunk selection
git-surgeon split HEAD \
  --pick <id1> <id2> -m "first commit" \
  --rest-message "remaining changes"

# Split with subject + body (multiple -m flags, like git commit)
git-surgeon split HEAD \
  --pick <id1> -m "Add feature" -m "Detailed description here." \
  --rest-message "Other changes" --rest-message "Body for rest."

# Split with line ranges (comma syntax or repeat ID for non-contiguous ranges)
git-surgeon split <commit> \
  --pick <id>:1-11,20-30 <id2> -m "partial split"

# Move a commit after another commit
git-surgeon move <sha> --after <target-sha>

# Move a commit before another commit
git-surgeon move <sha> --before <target-sha>

# Move a commit to the end of the branch
git-surgeon move <sha> --to-end

# Update git-surgeon to the latest version
git-surgeon update

# Split into three+ commits
git-surgeon split HEAD \
  --pick <id1> -m "first" \
  --pick <id2> -m "second" \
  --rest-message "rest"

Typical workflow

  1. Run git-surgeon hunks to list hunks with their IDs
  2. Use git-surgeon show <id> to inspect a hunk (lines are numbered)
  3. Stage and commit in one step: git-surgeon commit <id1> <id2> -m "message"
  4. Or stage separately: git-surgeon stage <id1> <id2>, then git commit
  5. To commit only part of a hunk, use inline ranges: git-surgeon commit <id>:5-30 -m "message"

Committing to another branch

Use commit-to when working in a worktree and you need to commit changes to a branch checked out elsewhere (e.g., main):

  1. Run git-surgeon hunks to list hunks
  2. Commit to another branch: git-surgeon commit-to main <id1> <id2> -m "message"
  3. The hunks are applied to the target branch's tree and discarded from the working tree
  4. Fails if the patch cannot be applied cleanly to the target branch

Picking the right folding command

You have...Use
Staged changesgit-surgeon amend <target>
One existing commit, defaulting to HEADgit-surgeon fold <target>
One or more named commitsgit-surgeon fold <target> --from <sha>

Folding existing commits into earlier commits

fold folds one or more existing commits into an earlier one. The source(s) (default: HEAD) are removed from history and their changes merge into the target. Intermediate commits stay untouched. Dirty working tree is autostashed. Refuses to run when the index already has staged changes.

  • git-surgeon fold <target> -- fold HEAD into target (most common)
  • git-surgeon fold <target> --from <commit> -- fold a specific non-HEAD commit
  • git-surgeon fold <target> --from <c1> <c2> <c3> -- fold multiple commits in one pass
  • Fails if the range contains merge commits
Using --blame to find the fold target

Use --blame to see which commit introduced the surrounding lines:

bash
git-surgeon hunks --blame

Output shows commit hashes for each line:

a1b2c3d src/auth.rs (+2 -0)
  8922b52  fn login(user: &str) {
  8922b52      validate(user);
  0000000 +    log_attempt(user);  # new line, not yet committed
  0000000 +    audit(user);        # new line, not yet committed
  8922b52  }

The context lines show 8922b52 -- that's the commit where this function was added. If your new lines belong with that change:

bash
git-surgeon commit a1b2c3d -m "add login logging"
git-surgeon fold 8922b52

Amending earlier commits with staged changes

amend folds staged changes into an earlier commit. For HEAD, amends directly; for older commits, uses autosquash rebase. Unstaged changes are preserved. For folding an existing commit instead, use fold.

  1. Stage desired hunks: git-surgeon stage <id1> <id2>
  2. Amend the target commit: git-surgeon amend <commit-sha>

Squashing commits

Squash collapses ALL commits from the target through HEAD into one, including any unrelated commits in that range. Preview with git log <target>..HEAD --oneline first. If the range is mixed, use fold --from <c1> <c2> ... to fold only named commits, or move --to-end the unrelated ones first.

  1. Squash commits from a target commit through HEAD: git-surgeon squash HEAD~2 -m "combined"
  2. Use multiple -m flags for subject + body: git-surgeon squash HEAD~1 -m "Subject" -m "Body paragraph"
  3. Target commit must be an ancestor of HEAD
  4. Use --force to squash ranges containing merge commits
  5. Uncommitted changes are autostashed and restored
  6. Author from the oldest commit is preserved by default; use --no-preserve-author for current user
Show full SKILL.md (236 more words)Show less

Undoing changes from commits

  1. Run git-surgeon hunks --commit <sha> to list hunks in a commit
  2. Undo specific hunks: git-surgeon undo <id> --from <sha>
  3. Or undo entire files: git-surgeon undo-file src/main.rs --from <sha>
  4. Changes appear as unstaged modifications in the working tree

Splitting commits

  1. List hunks in the commit: git-surgeon hunks --commit <sha>
    • For small commits, use --full to see all lines with line numbers in one call
  2. Split by picking hunks: git-surgeon split <sha> --pick <id1> -m "first" --rest-message "second"
  3. Use multiple -m flags for subject + body: --pick <id> -m "Subject" -m "Body paragraph"
  4. Use id:range syntax for partial hunks: --pick <id>:5-20
    • For non-contiguous lines, use commas: --pick <id>:2-6,34-37
  5. Works on HEAD (direct reset) or earlier commits (via rebase)
  6. Requires a clean working tree

Moving commits

move reorders commits in history. Useful for grouping related changes or moving a commit to a logical position after splitting.

  • git-surgeon move <sha> --after <target> -- place commit right after target
  • git-surgeon move <sha> --before <target> -- place commit right before target
  • git-surgeon move <sha> --to-end -- place commit at HEAD
  • Dirty working tree is autostashed
  • Fails if the range contains merge commits

Hunk IDs

  • 7-character hex strings derived from file path + hunk content
  • Stable across runs as long as the diff content hasn't changed
  • Duplicates get -2, -3 suffixes
  • If a hunk ID is not found, re-run hunks to get fresh IDs

© raine, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/git-surgeon of raine/git-surgeon.

Open the folder on GitHubat commit 798e80e

Compare with similar skills

Git Surgeon next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Git Surgeon compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Git Surgeon this skillraine/git-surgeon171—~2.3kAutomated safety check: PassMIT
Finishing a Development Branchobra/superpowers296k5 repos~1.9kAutomated safety check: PassMIT
Code Design Rationale Investigatorcursor/plugins10k9 repos~2.6kAutomated safety check: PassNone
Contributor-First PR MergeHKUDS/OpenHarness16k1 repos~847Automated safety check: PassMIT
Migrate Internal Package into GhostTryGhost/Ghost55k—~3.8kAutomated safety check: PassMIT
Create Pull Requestcline/cline70k1 repos~1.6kAutomated safety check: PassApache-2.0

Similar skills

  • Walks the last step of a branch: confirm tests pass, detect the git environment, ask how to integrate, carry out your choice and clean up the worktree.

    296k GitHub starsUsed in 5 repos~1.9k tokens
    DevelopmentAuto-check passed
  • Official

    Digs into why code is shaped the way it is by checking git history, pull requests and connected tools in parallel, then reporting a cited read on the tradeoffs.

    10k GitHub starsUsed in 9 repos~2.6k tokens
    DevelopmentAuto-check passed
  • Merges external GitHub pull requests while keeping the original author credited, and fixes conflicts after the merge instead of rewriting the contribution.

    16k GitHub starsUsed in 1 repo~847 tokens
    DevelopmentAuto-check passed
  • Moves a package from another TryGhost repository into Ghost as an internal workspace package while keeping its Git history, with checkpoints for the steps that need an administrator.

    55k GitHub stars~3.8k tokensUpdated today
    DevelopmentAuto-check passed
  • Opens a GitHub pull request from your current branch with the gh CLI, after reviewing the commits and diff and gathering the details the PR needs.

    70k GitHub starsUsed in 1 repo~1.6k tokens
    DevelopmentAuto-check passed
  • Git Merge Conflict Resolver

    tailcallhq/forgecode

    Resolves Git merge conflicts with a plan-first workflow that keeps both sides' intent, regenerates lock files and backs up deleted-but-modified files.

    7.6k GitHub starsUsed in 1 repo~4.5k tokens
    DevelopmentAuto-check passed

Works with

Categories

Questions about Git Surgeon

What does Git Surgeon do?

Non-interactive hunk-level git staging, unstaging, discarding, undoing, fold, amend, squash, commit splitting, and commit reordering. Git Surgeon is an agent skill from raine/git-surgeon. Non-interactive hunk-level git staging, unstaging, discarding, undoing, fold, amend, squash, commit splitting, and commit reordering.

When should I use Git Surgeon?

Git Surgeon fits situations like: selectively staging; reordering individual diff hunks by ID instead of interactively.

How do I install Git Surgeon in Claude Code?

Run `npx skills add raine/git-surgeon --skill git-surgeon -a claude-code`. Or copy the skill folder (skills/git-surgeon in raine/git-surgeon) into .claude/skills/git-surgeon in your project. Claude Code loads it when a task matches its description.

How do I install Git Surgeon in Codex?

Run `npx skills add raine/git-surgeon --skill git-surgeon -a codex`. Or copy the skill folder (skills/git-surgeon in raine/git-surgeon) into .agents/skills/git-surgeon in your project. Codex loads it when a task matches its description.

Can I use Git Surgeon in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add raine/git-surgeon --skill git-surgeon -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/git-surgeon, .gemini/skills/git-surgeon, .github/skills/git-surgeon and .opencode/skills/git-surgeon in your project.

What does Git Surgeon need to run?

Going by SKILL.md and its folder, Git Surgeon needs the command-line tools its instructions call (git).

Does Git Surgeon access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Git Surgeon safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Git Surgeon use?

Git Surgeon is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Git Surgeon use?

About 2.3k tokens (SKILL.md is roughly 9.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Git Surgeon?

Skills that share tags, products or a category with Git Surgeon: Finishing a Development Branch (obra/superpowers, 296k stars), Code Design Rationale Investigator (cursor/plugins, 10k stars), Contributor-First PR Merge (HKUDS/OpenHarness, 16k stars) and Migrate Internal Package into Ghost (TryGhost/Ghost, 55k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Git Surgeon?

raine (a GitHub user) maintains it in raine/git-surgeon, which has 171 GitHub stars. The repository was last updated on July 26, 2026.

Source: raine/git-surgeon on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.