git-surgeon CLI

A CLI and skill for precise non-interactive git: commit single hunks, split commits and fold fixes into earlier ones.

  • 192 ★ on the repository
  • Last commit
  • MIT
CLI

Broad access

Why this level

  • The `discard`, `fold`, `split`, `squash` and `move` commands change the working tree and git history with no simple rollback.
  • The tool installs through a script fetched from the network.
All reasons and checks

raine/git-surgeon

Install

Manual install

curl -fsSL https://raw.githubusercontent.com/raine/git-surgeon/main/scripts/install.sh | bash

The first option in Quick start. Alternatives: `cargo install git-surgeon` and Homebrew. Then `git-surgeon install-skill --claude`.

Access and checks

How we review

Broad accessThe tool can change data, run commands or handle secrets.

  • The `discard`, `fold`, `split`, `squash` and `move` commands change the working tree and git history with no simple rollback.
  • The tool installs through a script fetched from the network.

This is third-party code. Review the repository files before installing.

What it does

git-surgeon addresses agents that cannot use `git add -p`. `git-surgeon hunks` lists hunks with short IDs, and `stage`, `unstage`, `discard` and `commit` act on them by ID. Selected hunks, or single lines inside a hunk, can be committed in one step. For history work there are `split`, `fold`, `amend`, `squash`, `reword`, `move` and `undo`: a mixed commit splits into focused ones, a fix folds into an earlier commit and hunks are reversed out of past commits. `commit-to` puts hunks on another branch without checking it out. The skill teaches an agent to call the tool instead of destructive workarounds with `git checkout`.

Who it is for. Developers who ask Claude Code, Codex or OpenCode for tidy separate commits instead of losing edits to file resets.

Good fit when

  • A diff mixed a refactor with a new feature and must become two commits.
  • A review typo fix has to be folded into a week-old commit.
  • A committed hunk turned out unwanted and is reversed precisely.
  • A change must land on a neighboring branch without switching to it.
  • An agent burns turns on clever workarounds for `git add -p`.

Not a fit when

  • The repository uses Jujutsu; the author points to jj-hunk-tool.
  • History has already been pushed to a shared branch and rewriting it would break colleagues.
  • Whole-file commits are enough and plain `git commit` is simpler.

Example request

Split my changes into two commits: the refactor on its own and the new feature on its own.

Limitations

The tool operates on a git repository and rewrites history with `fold`, `split`, `squash` and `move`, so run them on local branches not yet shared with colleagues. Hunk IDs change with the diff, and the agent calls `hunks` again after each edit. The skill installs with a separate `install-skill` command for Claude Code, OpenCode or Codex. It does not suit Jujutsu. The shell installer piped from `curl | bash` requires trust in the source; Cargo and Homebrew variants exist.

How to disable. Remove the binary (`cargo uninstall git-surgeon` or `brew uninstall git-surgeon`) and the `git-surgeon` skill folder from the agent's skills directory. For the Claude Code plugin run `claude plugin uninstall git-surgeon@git-surgeon`.

FAQ

How do I install git-surgeon?

Run `cargo install git-surgeon` or `brew install raine/git-surgeon/git-surgeon`. Then `git-surgeon install-skill --claude` installs the skill for Claude Code, with `--opencode` and `--codex` for other agents.

How is it better than git add -p?

It needs no interactivity. The agent sees hunks with IDs and commits them with `git-surgeon commit` without a dialog it cannot use.

Can single lines be committed?

Yes, a line range inside a hunk can be selected. The README has an example of splitting one hunk across several commits.

How do I install it as a Claude Code plugin?

Run `claude plugin marketplace add raine/git-surgeon`, then `claude plugin install git-surgeon@git-surgeon`.

Does it work with Jujutsu?

No. For Jujutsu the author recommends a separate project, jj-hunk-tool.

Discussion

No questions or reviews yet.

CLI tools

A skill that splits changes into logical Conventional Commits and safely handles branches, pushes and pull requests.

SkillExtended access105Repository stars

gitai is an open source-control server for hundreds of agents: landing by compare-and-swap, server-side history and the graft CLI.

CLIExtended access1KRepository stars

multi-gitter runs one script across multiple Git repositories and creates pull requests for the resulting file changes.

CLIExtended access1.3KRepository stars

A local gate in front of git push: the branch goes through review, tests, docs and lint in a separate worktree before it reaches the remote with a PR

CLIBroad access9.2KRepository stars

Three UNIX tools: a directory fork without copying, a sandboxed agent run and a patch with the changes it made.

CLIExtended access64Repository stars

A skill and plugin for Git and GitHub: branches, Conventional Commits and a pull request path to a green merge.

SkillExtended access59Repository stars

README in short

The README shows a typical agent failure, resetting a file to make separate commits, and contrasts it with working through git-surgeon. A table says when to pick `amend` and when `fold`.

README badge

Original SKILL.md

---
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> ...

Report a problem