Cherry-pick a commit onto the current branch. On conflict git leaves the
cherry-pick in progress, so the error surfaces for the caller to tell the
user to resolve and git cherry-pick --continue.
Force-delete a branch. Use only once review state confirms it landed: a
squash merge leaves the commits non-ancestry-merged, so git branch -d
would refuse even though the work is in.
How to hand a branch back, as a command the user can paste. Detaching is what
the guards lead with because it works on every worktree: git worktree remove
refuses on the main one, and moving the operation into the holding worktree
only helps when that worktree is the only one in the way.
A unified-0 diff against HEAD: just the staged changes when cached,
otherwise all tracked changes (staged and unstaged). Zero context lines
so each hunk’s pre-image range pinpoints exactly the lines it touches.
Lines added and deleted in branch relative to base, over the symmetric
base...branch range a forge uses for a review diff (the branch’s own work
since it diverged). Binary files, which --numstat marks with -, count
as zero.
Render a worktree path for a message the user may paste back as a command.
Sibling worktrees are the common layout and ../wt-a reads better than a
long absolute path. Only exact prefix matches are shortened, so the result is
always a usable path - never a guess.
Collapse worktree paths to the distinct places involved, so a message about
three branches held by one worktree suggests freeing it once, not three times.
Refresh the remote-tracking refs (<remote>/<branch>) for branches that
exist on remote, in a single fetch. Branches absent from the remote (a
freshly created top of stack that was never pushed) are dropped rather than
failing the whole fetch. A no-op when none of them are on the remote.
Resolve path under the repo’s common git dir, which all linked
worktrees share, rather than the per-worktree dir git_path returns. Use
this for state that guards or mirrors the shared config (branch.*), so
every worktree of a repo agrees on one file.
An absolute path under the repo’s common git dir. Callers that hand a path to
another process (a worktree location, a command’s working directory) need it
absolute, since a relative one would be read against the wrong directory.
Whether this command is running inside a linked worktree rather than the
main checkout. Best effort: an unreadable root reads as the main worktree,
which is where most runs happen.
Whether the working directory is inside a git work tree. Used for a clean
“not a git repository” message instead of letting git’s raw error surface
from the first command that needs the repo.
Whether path is the repo’s main worktree. Worth telling apart because
git worktree remove refuses on it, so any advice that would free a branch
by removing its worktree is a dead end there.
The anchor for repo-wide paths that must resolve the same from every
worktree. repo_root answers “where am I”, which inside a linked worktree
is that worktree - so a default derived from it would nest a new worktree
under the one it was created from. Falls back to the root when the listing
cannot be read, which is where a repo with no linked worktrees lands anyway.
Force-push branches (with lease), returning the branches that actually
landed. Normally that is all of them; the exception is the merge-queue
backstop below, which drops a held-back branch from the returned set so the
caller never reports a branch as both held and pushed.
Whether a rebase is actually paused in this worktree. Distinguishes a real
conflict from git-stk merely having left state on file - git refuses to
rebase a branch another worktree holds, which fails the run without ever
starting a rebase to continue or abort.
Rebase only the commits after base, replaying base..branch onto
parent. Used when the recorded fork point is known so commits that
landed upstream by squash or rebase are not replayed.
The commits tracking (a <remote>/<branch> ref) has that branch lacks
and that have no patch-equivalent already on branch - the commits a
force-push would silently drop, e.g. one committed straight on the host’s
web UI. (short-sha, subject) oldest-first, the order to cherry-pick them.
Empty in the normal post-rebase case, where every remote commit is
reproduced locally under a new hash.
Whether two paths name the same place. Never compare worktree paths with
==: git reports its own resolved form, which differs from anything we
build ourselves - /var against /private/var on macOS, forward against
back slashes on Windows - so exact equality quietly reports “different”.
Add a detached worktree at path, parked on commit. Detached on purpose:
it holds no branch, so it cannot collide with the user’s checkout or any
other worktree.
Branches checked out in linked worktrees other than this one, paired with
the directory holding each. Git refuses to switch to, rebase, or delete a
branch another worktree holds, so callers check this before those.
Store content as a single-file commit and point reference at it, so the
data rides along a normal ref push. Orphan each time: the ref just moves to
the new commit (callers force-push it, as it is regenerable).