Run the fixed git steps around work on an existing branch — check it out fast-forward only and record the remote tip it saw, rebase it onto origin/<base>, finish or abort a rebase stopped on conflicts, push it against that recorded tip (refusing a branch behind it, with a lease exactly when it is not an ancestor of HEAD) and verify the push landed, release the local branch and its record at the end of a run, and reclaim a branch another worktree still holds after its agent ended, refusing while that work is unfinished or the holder's lock names a running process. Resolving a conflict stays with the caller.
Install
npx skillscat add thevoskamps/claude-plugins-marketplace/git-branch-sync Install via the SkillsCat registry.
Git Branch Sync
The git steps an agent runs around its own work on a branch that
already exists on origin, as one script with one exit-status contract
the caller branches on. What the script does not do is resolve a
conflict: that is judgment, and stays with the caller, which edits the
conflicted files and hands the resolved paths back to continue.
Invocation
/git-tools:git-branch-sync <subcommand> [<argument>…]Run the bundled script, spelled as a bare name, from inside the
checkout:
git-branch-sync checkout <branch>
git-branch-sync rebase <base>
git-branch-sync continue <path>…
git-branch-sync abort
git-branch-sync push [--exclude <pathspec>]…
git-branch-sync release <branch>
git-branch-sync reclaim [--holder-ended] [--exclude <pathspec>]… <branch>No subcommand ever opens an editor.
Subcommands
checkout <branch>— fetchesorigin, checks<branch>out,
and fast-forwards it toorigin/<branch>. With no local<branch>,
creates it trackingorigin/<branch>. A local branch already ahead
oforigin/<branch>is checked out as it is. It then records theorigin/<branch>tip it saw in the refrefs/git-branch-sync/<branch>, the recorded tippushdecides
against. When another worktree holds<branch>— has it checked out,
or is rebasing it — it exits 13 naming that worktree's path, and
checks out and records nothing.rebase <base>— fetchesoriginand rebases the current branch
ontoorigin/<base>. It leaves the recorded tip alone.continue <path>…— stages the given paths, then commits the
stopped commit underREBASE_HEAD's message and author and lets the
rebase continue, exiting asrebasedoes on the next stop. Each path
is taken literally, never as a pattern, and relative to the top level
of the working tree from whatever directorycontinueruns in, asrebaseprints it, so a pathrebaseprinted can be passed back as
it stands. When the staged resolution leaves
the stopped commit with no change, the commit is skipped instead, as
a rebase drops a commit that becomes empty.abort— aborts the rebase in progress, leaving the branch
checked out at its pre-rebase tip.push— decides against the tipcheckoutrecorded for the
current branch, never a tip it fetches itself, so a commit another
writer pushed after the checkout is refused rather than replaced.
Unless it refuses as exits 11 and 12 state, it pushes the current
branch toorigin/<branch>: with--force-with-lease=<branch>:<the recorded tip>when the recorded tip is not an ancestor of HEAD, and a
plain push otherwise, which succeeds when there is nothing new.
Ancestry alone decides; nothing records whether a rebase ran. After a
successful push it records the pushed tip, then fetchesoriginand
verifies thatorigin/<branch>equals local HEAD and that the working
tree is clean. It never uses--forceor--mirror, and never moves
the local branch, so no exit ofpushremoves a local commit.--exclude <pathspec>, repeatable, leaves the paths it matches,
tracked or untracked, out of that clean-tree check and changes
nothing else; each pathspec is relative to the top level of the
working tree, from whatever directorypushruns in. Pass it for
files you own but never commit.release <branch>— detaches HEAD, deletes the local<branch>
and deletes its recorded tip, if any, releasing the claim that
otherwise keeps every other worktree from checking the branch out. It
deletes whatever the branch holds: run it only once the branch's work
is pushed, or when there was none.reclaim [--holder-ended] [--exclude <pathspec>]… <branch>—
releases the claim a worktree whose agent ended withoutrelease
still holds. It fetchesoriginand finds the holder: the worktree
that has<branch>checked out, or is rebasing it. Then, in order:- When the holder is mid-rebase, or has uncommitted changes outside
the paths--excludematches, relative to the holder's top level,
or the local<branch>has commitsorigin/<branch>lacks — with
or without a holder — it exits 14 and changes nothing. A holder
has a working tree only when git run in its directory resolves to
that worktree itself — the top level is the holder's path and the
common git dir is this repository's — so one whose directory is
gone, or whose.gitis missing or names a gitdir that is gone,
has none. A holder with a working tree has its rebase state read
where git run in it puts it. One with none is never dirty, and its
rebase state is read from its administrative directory: the one
under the common git dir'sworktrees/whosegitdirfile names
the holder's.git, an absolute path as written and a relative
one, asworktree.useRelativePathswrites it, against that
administrative directory, both compared with symlinks resolved.
Finding the holder reads each worktree's rebase state the same way. - When the holder's lock reads
claude agent agent-<id> (pid <pid> start <date>)and<pid>is a running process whose start time
equals<date>, runs of spaces collapsed, and--holder-endedis
absent, it exits 15 and changes nothing. No lock, a lock in any
other form, or a PID that is gone or started at another time is no
evidence of life. - Otherwise it detaches the holder's HEAD — through the worktree's
administrative directory when it has no working tree — deletes the
local<branch>and its recorded tip, and prints the holder's path,
or nothing when no worktree held the branch.
--holder-endedasserts that the caller knows the holder's agent has
ended; it overrides step 2 and never step 1, since a live PID names
the session that spawned the agent, and an agent can die inside a
live session. It removes no worktree and no lock.- When the holder is mid-rebase, or has uncommitted changes outside
Exit status
Each status below is produced by exactly the condition it names, with
the stderr line shown, prefixed with the program's name and a colon.
Stdout is empty
on every status but 3, and on a reclaim exit 0 that released a holder,
where it is the holder's path.
| Exit | Condition | Stderr |
|---|---|---|
| 0 | success | — |
| 1 | a failure the script did not classify, such as a failed fetch, no origin/<branch> on checkout or origin/<base> on rebase, a dirty tree blocking a checkout, or a push the remote refused for its own reason; git's own status is never passed through |
names the failed command or condition |
| 2 | usage error: an unknown subcommand, or a missing or extra argument; nothing was run | `<subcommand>` is not a subcommand git-branch-sync takes., `<subcommand>` takes <n> argument(s), not <m>., `continue` needs at least one resolved path., `--exclude` needs a pathspec., `push` takes no argument `<argument>`., `reclaim` takes no option `<option>`. or No subcommand was supplied., then the synopsis |
| 3 | rebase or continue: the rebase stopped on conflicts. Stdout is the conflicted paths, one per line, verbatim and unquoted, and nothing else |
the rebase stopped on conflicts in the paths on stdout |
| 4 | checkout: the local branch has diverged from origin/<branch>; nothing was checked out, reset or recorded |
local <branch> (<sha>) has diverged from origin/<branch> (<sha>); nothing was reset |
| 5 | continue: a conflicted path remains unresolved after staging the given paths; nothing was committed |
the unresolved paths, one per line, then a conflicted path is still unresolved: the paths above |
| 6 | continue or abort: no rebase is in progress |
no rebase is in progress |
| 7 | rebase or push: no branch is checked out |
no branch is checked out (HEAD is detached) |
| 8 | push: rejected because origin/<branch> moved past the recorded tip — a lease or fast-forward failure |
the push was rejected: origin/<branch> moved past the recorded tip (<sha>) |
| 9 | push: verification failed, local HEAD differs from the remote tip |
local HEAD <sha> differs from origin/<branch> <sha> |
| 10 | push: verification failed, the working tree is dirty outside the paths --exclude matches |
the working tree is dirty after the push |
| 11 | push: the local branch is behind the recorded tip — HEAD is a strict ancestor of it; nothing was pushed |
local <branch> (<sha>) is behind its recorded tip (<sha>); nothing was pushed |
| 12 | push: no tip is recorded for the branch — checkout did not run in this clone; nothing was pushed |
no tip is recorded for <branch>: run `checkout <branch>` first; nothing was pushed |
| 13 | checkout: another worktree holds the branch — has it checked out or is rebasing it; nothing was checked out or recorded |
<branch> is held by the worktree at <path> |
| 14 | reclaim: the branch carries unfinished work — the holder is mid-rebase or has uncommitted changes outside the paths --exclude matches, or the local branch has commits origin/<branch> lacks; nothing was changed, whatever --holder-ended says |
<branch>, held by the worktree at <path>, has unfinished work: <what it found>; nothing was changed, or held by no worktree in place of the holder |
| 15 | reclaim: the holder's lock names a running process with a matching start time, and --holder-ended is absent; nothing was changed |
<branch> is held by the worktree at <path>, whose lock names the running process <pid>; nothing was changed |
On 3 the rebase is still in progress: resolve the paths and runcontinue, or run abort. On 5 the given paths stay staged and the
rebase stays in progress.