Skip to content

create_pull_request should reuse existing branch when preserve-branch-name is enabled #29152

@mrjf

Description

@mrjf

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:

  1. The agent can't push directly (git credentials are cleaned before the agent step)
  2. The branch is long-lived and intentionally reused across iterations
  3. 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:

  1. Checks out the branch, merges main, commits new changes
  2. Needs to push to the branch (but can't — no git credentials during agent step)
  3. 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

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions