feat: support rebasing branches checked out in worktrees#145
Open
abersnaze wants to merge 1 commit intomsiemens:masterfrom
Open
feat: support rebasing branches checked out in worktrees#145abersnaze wants to merge 1 commit intomsiemens:masterfrom
abersnaze wants to merge 1 commit intomsiemens:masterfrom
Conversation
When a branch is checked out in a separate git worktree, `git checkout` fails with 'already used by worktree'. Instead of checking out such branches in the main repo, detect them via `git worktree list --porcelain` and perform the rebase (or fast-forward merge) directly in the worktree directory. This handles: - Fast-forward: runs `git merge --ff-only` in the worktree - Rebase: stashes worktree changes if dirty, rebases, then unstashes Fixes the error: fatal: '<branch>' is already used by worktree at '<path>' Co-Authored-By: Oz <oz-agent@warp.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a branch is checked out in a separate git worktree,
git upfails with:This happens because
rebase_all_branches()tries togit checkoutthe branch, which git refuses since it's already checked out in another worktree.Solution
Before attempting checkout, build a map of branches to their worktree paths via
git worktree list --porcelain. For branches found in worktrees:git merge --ff-onlydirectly in the worktreeThis matches the existing behavior for non-worktree branches — failed rebases are left for the user to resolve.
Changes
gitup.py: Added_build_worktree_map()and_rebase_in_worktree()methods; modifiedrebase_all_branches()to dispatch worktree branches accordinglytest_worktree.py: Tests both fast-forward and rebase scenarios with a worktree branchTesting
All 37 tests pass (36 existing + 1 new).
Warp conversation
Co-Authored-By: Oz oz-agent@warp.dev