Problem
When preserve-branch-name: true is set and the target branch already exists on the remote, create_pull_request refuses to push:
Git push failed: Remote branch "autoloop/build-tsb-pandas-typescript-migration" already exists
and preserve-branch-name is enabled. Refusing to silently rename the branch.
This blocks workflows like autoloop where:
- The agent can't push directly (git credentials are cleaned before the agent step)
- The branch is long-lived and intentionally reused across iterations
- There's no open PR (previous one was merged), so the agent correctly calls
create_pull_request rather than push_to_pull_request_branch
The handler falls back to creating an issue instead of a PR, which defeats the purpose.
Expected behavior
When preserve-branch-name is enabled and the named branch already exists on the remote, create_pull_request should force-push the patch to the existing branch and create the PR from it. The branch name matching is the point of preserve-branch-name — reusing the branch is the intended behavior, not a conflict.
Context
Autoloop maintains one long-lived branch per program (autoloop/{program-name}). Each iteration:
- Checks out the branch, merges main, commits new changes
- Needs to push to the branch (but can't — no git credentials during agent step)
- Calls
create_pull_request to push via safe-outputs and create a PR
This works on the first iteration (branch doesn't exist yet). On subsequent iterations after a PR merge, the branch still exists on the remote but has no open PR. The agent calls create_pull_request again, which should push to the existing branch and open a new PR.
Example
Workaround
Manually delete the stale remote branches before each iteration. Not viable for automated loops.
Related
Problem
When
preserve-branch-name: trueis set and the target branch already exists on the remote,create_pull_requestrefuses to push:This blocks workflows like autoloop where:
create_pull_requestrather thanpush_to_pull_request_branchThe handler falls back to creating an issue instead of a PR, which defeats the purpose.
Expected behavior
When
preserve-branch-nameis enabled and the named branch already exists on the remote,create_pull_requestshould force-push the patch to the existing branch and create the PR from it. The branch name matching is the point ofpreserve-branch-name— reusing the branch is the intended behavior, not a conflict.Context
Autoloop maintains one long-lived branch per program (
autoloop/{program-name}). Each iteration:create_pull_requestto push via safe-outputs and create a PRThis works on the first iteration (branch doesn't exist yet). On subsequent iterations after a PR merge, the branch still exists on the remote but has no open PR. The agent calls
create_pull_requestagain, which should push to the existing branch and open a new PR.Example
build-tsb-pandas-typescript-migrationautoloop/build-tsb-pandas-typescript-migrationexists (0 ahead, 99 behind main — fully merged)create_pull_requestwithbranch: autoloop/build-tsb-pandas-typescript-migrationWorkaround
Manually delete the stale remote branches before each iteration. Not viable for automated loops.
Related
create_pull_requestpatch limit and addmax-patch-filesconfig #28472 — max-patch-files config (shipped in v0.71.2)