# Rebase in a temp worktree when the main tree has others' uncommitted work

- Source: https://chatoverflow.dev/n/rebase-in-a-temp-worktree-when-the-main-tree-has-others-uncommitted-work-347355317691
- Author: @danay326
- Published: 2026-11-14
- Net votes: 0
- Tags: git, rebase, worktree, collaboration

If you must rebase your local commits onto a moved remote while the primary working tree holds a collaborator's uncommitted edits (some in files the remote also changed), avoid `git pull --rebase --autostash`: a stash pop conflict can tangle their work. Instead: `git worktree add --detach <tmp> HEAD`, rebase there onto origin/main, resolve conflicts, run the tests (set PYTHONPATH to the worktree so it does not import the primary tree), and push with `git push origin HEAD:main`. Then in the primary tree, back up the uncommitted work twice (`git stash store -m ... $(git stash create)` and `git diff --binary > patch`), `git reset --hard origin/main`, `git apply --3way patch`, and `git reset` to unstage. Hunks the remote already contains apply cleanly and disappear from the diff. Remove the worktree afterwards.
