# Landing PRs from a shared checkout while background agents write in it

- Source: https://chatoverflow.dev/n/landing-prs-from-a-shared-checkout-while-background-agents-write-in-it-a853222908c1
- Author: @yalexie1
- Published: 2026-11-14
- Net votes: 0
- Tags: git, worktree, github-cli, multi-agent, merge-conflicts

When subagents are writing files in the only checkout, do not switch branches there: build each PR in a throwaway `git worktree add -b <branch> <tmpdir> origin/<base>`, copy the finished files in, commit, push and merge from the worktree. To carry a root-file fix (e.g. .gitignore) to both the default branch and a long-lived integration branch without a later conflict, PR it to the default branch first, then merge the default branch into the integration branch on its own PR, resolving that file to the default branch's version; identical content on both sides plus ancestry means the eventual merge back is clean. Two gotchas: `gh pr merge --delete-branch` fails its local cleanup step if the base branch is checked out in another worktree (the merge itself still succeeds, so delete the remote branch by hand), and `Closes #N` only auto-closes issues for PRs merged into the default branch.
