Update Base Branch
Move the current worktree onto its intended base branch and update it without discarding work or guessing across ambiguous branches, remotes, or worktrees.
Protect the current worktree
Inspect the current branch, status, and all worktrees first. Stop if the current worktree has staged, unstaged, or untracked changes. Ask the user to commit or stash them; do not fetch, select a target, switch branches, or stash automatically while local work is unprotected.
Resolve the target
- Inspect local and remote branches and upstream configuration.
- Use a branch the user named. Otherwise select the current worktree's established base or integration branch when repository evidence makes it unambiguous. Treat an available
devbranch as the usual default candidate, not as permission to ignore conflicting evidence. - Ask the user which branch to use when the target remains ambiguous. Include the likely candidates and their upstreams.
- Keep the operation inside the current worktree. If the desired branch is checked out in another worktree, ask for a different worktree-specific base branch or tell the user to run the operation in the owning worktree. Do not update the other worktree implicitly.
Resolve the upstream
- Resolve the selected local branch's configured upstream. Do not assume a remote named
origin. - If the branch has no upstream, or the same branch name exists on multiple remotes without a clear choice, ask which remote branch should be authoritative.
- Never reset, force-switch, delete, or rewrite commits to reach the remote tip.
Update the branch
- Fetch only after the target branch and authoritative remote are resolved.
- Before switching, verify that the selected local branch is an ancestor of the fetched upstream. If it contains commits absent from the upstream, whether ahead or diverged, stop and report both sides instead of choosing a reconciliation strategy.
- Switch the current worktree to the selected local branch. If the user selected a remote-only branch, create its local tracking branch without overwriting an existing ref.
- Fast-forward the local branch to the fetched upstream. Require a fast-forward-only update.
- Verify that:
- the current worktree is on the selected branch;
- its upstream is the resolved remote branch;
- local
HEADequals the fetched upstream tip; and - the worktree remains clean.
Report the branch, upstream, and resulting commit. If any assertion fails, report the exact state and do not claim completion.