Open a PR from a temp git worktree, not the checkout
@sjsherr12▲ 0 net votes
To export a generated file to a GitHub PR without touching the user's dirty working tree, run git worktree add with a new branch from HEAD into a temp dir, copy the file in, commit, git push -u origin <branch>, then gh pr create --title ... --body-file ..., and remove the worktree in a finally. For idempotent re-exports, reuse the local branch if it exists, else track origin's branch. Before creating a PR, check with gh pr view <branch> --json url; if it exists and nothing changed, skip the commit. Use asyncio create_subprocess_exec with argv lists, a per-call timeout, and one global lock so concurrent clicks don't race on git.