Skip to content

Update branches in place and use each branch's own base (works in worktrees) - #37

Merged
martyzz1 merged 4 commits into
masterfrom
feature/ENG-2110-pullrequest-in-worktree
Nov 7, 2026
Merged

martyzz1 merged 4 commits into
masterfrom
feature/ENG-2110-pullrequest-in-worktree

Conversation

@martyzz1

@martyzz1 martyzz1 commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Why

git pullrequest brought a branch up to date by checking out the base branch, pulling it, and checking the feature branch out again. Git won't check out a branch that is already checked out in another worktree, so this failed in a worktree whenever main was checked out somewhere else. That's the normal setup for Harper's repos, which have many sibling worktrees. It also assumed every branch came from gitfeatures.masterBranch. A branch cut from a release branch was therefore merged with main, and its PR was opened against main.

What changes

  • git pullrequest updates the branch in place. It runs git fetch origin <base>, then git merge origin/<base>, or git rebase origin/<base> with strategy = rebase. It never checks out the base branch. On conflicts it still stops, and now says how to finish for each strategy. It catches rebase conflicts too, and other git failures print git's own message instead of a traceback.
  • Each branch has its own base branch, kept in git config as branch.<name>.gitfeaturesBase:
    • git feature new and git release/stable/hotfix new record the branch they were run from.
    • git pullrequest takes the base from --base <branch>, then the recorded value, then git's reflog (Created from origin/release_x) for branches made outside gitfeatures. If none of those gives an answer, it asks whether the base is masterBranch instead of assuming it.
    • It records what it used, updates from origin/<base> and opens the PR against <base>. The API call, the GitHub compare URL and Bitbucket's dest all use it.
  • git feature finish works out the base the same way and also takes --base. It checks the branch is merged into origin/<base> before moving off it. It then switches to the base branch, or detaches at origin/<base> when another worktree has the base branch checked out.
  • git feature finish when origin already deleted the branch (e.g. GitHub's automatic delete after a merge): it now deletes the local branch and the stale origin/<branch>, where before it stopped with the local branch still there.

Behaviour change to note

git pullrequest now asks once ("Was it main? [y/n]") for a branch whose start point it can't tell, where it used to assume main silently. This applies when gitfeatures didn't create the branch and git only logged Created from HEAD. The answer is recorded, so it's asked only once per branch.

Tests

tests/test_pullrequest.py has 10 tests, mostly with the base branch checked out in another worktree:

  • merge, rebase, and conflicts with each strategy
  • refusing to run on the base branch
  • a branch from feature new off a release branch
  • a branch made with git worktree add -b (base taken from the reflog)
  • an unknown base fixed with --base
  • feature finish against its own base, from a worktree, and after origin deleted the branch

Each was checked to fail before its fix. pre-commit run --all-files and pytest pass, with 71 tests.

README ("Base branches" section, command reference, troubleshooting) and CHANGELOG are updated.

🤖 Generated with Claude Code

martyzz1 and others added 4 commits November 7, 2026 12:26
…he base

When the branch is behind origin/<base>, fetch the base and merge
origin/<base> into the current branch (or rebase onto it with
strategy = rebase) rather than checking out the base branch, pulling it
and checking the feature branch out again. Git refuses to check out a
branch that is checked out in another worktree, so the old flow failed
in worktrees.

Conflict instructions now say how to finish for each strategy, rebase
conflicts are detected too (stderr is captured), and other git failures
exit with git's message instead of a traceback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
git pullrequest assumed every branch came from gitfeatures.masterBranch,
so a branch cut from a release branch was merged with, and had its PR
opened against, main.

Each branch now has a base, kept in branch.<name>.gitfeaturesBase.
git feature new and git release/stable/hotfix new record the branch
they were run from. git pullrequest takes the base from --base, the
recorded value, or git's reflog ("Created from origin/release_x") for
branches made outside gitfeatures; failing those it asks whether the
base is masterBranch rather than assuming it. It records what it used,
updates the branch from origin/<base> and opens the PR against it.
git feature finish checks the branch is merged into its own base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
finish_feature checked out masterBranch before anything else, which
fails in a git worktree while the base branch is checked out in another
worktree, and left you on the base branch even when it then refused.

It now resolves the base the same way as git pullrequest (and takes
--base), checks the branch is merged into origin/<base> before moving
off it, then switches to the base branch if no worktree has it checked
out, or detaches at origin/<base> if one does. Finishing a named branch
that is checked out in another worktree stops with that worktree's path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When GitHub deletes a branch after its PR is merged, `git push origin
:<branch>` fails and finish exited before deleting the local branch.
It now checks origin with ls-remote first; if the branch is already gone
it says so, drops the stale origin/<branch> ref and deletes the local
branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martyzz1
martyzz1 merged commit ce03922 into master Nov 7, 2026
12 checks passed
@martyzz1
martyzz1 deleted the feature/ENG-2110-pullrequest-in-worktree branch November 7, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant