agentleFS
vladcheckvladcheck/agentic/skills/git-rebuild-branch/SKILL.md

git-rebuild-branch

Skill1 starsChanged 10 days agoMITView on GitHub

Rebuild a git branch by cherry-picking only its unique commits onto another branch, e.g. a feature branch onto main minus inherited commits.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If any of the first two is missing, ask the user before proceeding.

    line 20
  2. Very specific:

    No ignore branch: <target>..<source> (commits in source, not in target).

    line 25
  3. Distinctive:

    Do NOT run anything until the user approves.

    line 53
  4. Very specific:

    Execute one command at a time: Run each command as a separate invocation.

    line 54
  5. Very specific:

    If cherry-pick hits a conflict, stop and surface it — resolve, then git cherry-pick --continue.

    line 56
  6. Distinctive:

    Prefer the earliest recovery point: the further you get, the more you rely on the saved SHA / reflog.

    line 81
  7. Very specific:

    Deleting the source branch before the rebuild succeeds: Only run git branch -D <source> after all cherry-picks land.

    line 87
  8. Very specific:

    Skipping the preview: Always show git log --oneline <range> so the commit selection is confirmed before any destructive step.

    line 88

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

git-rebuild-branch

Rebuild a branch by cherry-picking only the commits that are unique to it onto a target branch, then swap the rebuilt branch back into place under the original name.

Inputs (collect all before acting)

  1. Target branch — the branch to cherry-pick onto (e.g. main).
  2. Source branch — the branch whose commits you want (e.g. B).
  3. Ignore branch (optional) — a branch whose commits must be excluded (e.g. A). Given main -> A -> B, ignoring A keeps commits in B that are NOT in A.

If any of the first two is missing, ask the user before proceeding.

Commit range

  • Ignore branch given: <ignore>..<source> (commits in source, not in ignore).
  • No ignore branch: <target>..<source> (commits in source, not in target).

git cherry-pick <range> applies these oldest-first automatically.

Workflow

  1. Preview the commits so the user can confirm they are correct: git log --oneline <range>
  2. Build the command list using a temporary branch name (<source>-rebuilt). Every command below is mandatory and part of the sequence — the safety anchor and verifications are not optional extras:
    git log --oneline <range>
    git rev-parse <source>
    git checkout <target>
    git rev-parse --abbrev-ref HEAD
    git checkout -b <source>-rebuilt
    git cherry-pick <range>
    git status
    git log --oneline <target>..HEAD
    git branch -D <source>
    git branch --list <source>
    git branch -m <source>-rebuilt <source>
    git log --oneline <target>..<source>
  3. Get approval. Present exactly:

    Here is what I'm going to do: <commands> Do you approve this?

    Do NOT run anything until the user approves.

  4. Execute one command at a time. Run each command as a separate invocation. Never chain with &&, ;, or ||. After each command, confirm its result matches the table below before running the next.
  5. Save the output of git rev-parse <source> (step 2, second command) — this SHA is the backtracking escape hatch.
  6. If cherry-pick hits a conflict, stop and surface it — resolve, then git cherry-pick --continue. Never --skip or --abort without asking.

Expected result per command

CommandExpect
git rev-parse <source>a SHA — save it (backtracking anchor)
git checkout <target> → next git rev-parse --abbrev-ref HEAD<target>
git checkout -b <source>-rebuiltbranch created; HEAD is <source>-rebuilt
git cherry-pick <range> → git status + git log --oneline <target>..HEADclean tree; same commits (minus SHAs) as the preview
git branch -D <source> → git branch --list <source>empty
git branch -m <source>-rebuilt <source><source> exists, <source>-rebuilt gone
Final git log --oneline <target>..<source>exactly the intended commits

Backtracking

The saved SHA from git rev-parse <source> lets you undo everything — the original commits are not garbage-collected while that SHA is known.

SituationRecovery
Cherry-pick conflict you don't want to resolvegit cherry-pick --abort, then git checkout <target> and delete the temp branch — original <source> is untouched.
Rebuilt branch looks wrong, source NOT yet deletedgit checkout <source>; git branch -D <source>-rebuilt. Nothing lost.
Already deleted/renamed and result is wronggit branch -f <source> <saved-SHA> to restore the original, then remove the bad branch.
Lost the SHA toogit reflog — find the pre-rebuild <source> entry and git branch -f <source> <reflog-SHA>.

Prefer the earliest recovery point: the further you get, the more you rely on the saved SHA / reflog.

Common mistakes

  • Wrong range direction. A..B = commits reachable from B but not A. Reversing it drops everything you wanted.
  • Chaining commands. The user requires one command per invocation; a chained failure leaves the repo half-migrated.
  • Deleting the source branch before the rebuild succeeds. Only run git branch -D <source> after all cherry-picks land.
  • Skipping the preview. Always show git log --oneline <range> so the commit selection is confirmed before any destructive step.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.