Skip to content

PR checkout fails due to branch name collision after #851 #930

@kirisame-wang

Description

@kirisame-wang

Describe the bug

PR #851 introduced a bug where PR checkout fails if the PR branch name conflicts with existing branches in the base repository.

The new checkout strategy git fetch origin pull/${number}/head:${branchName} attempts to create a local branch with the PR's branch name, which fails when that branch name already exists locally or remotely in the base repo.

To Reproduce

Steps to reproduce the behavior:

  1. Create a branch named feature/my-feature in your base repository
  2. Create a PR (from same repo or fork) using the same branch name feature/my-feature
  3. Trigger the claude-code-action workflow on that PR
  4. See error:
git fetch origin --depth=20 pull/123/head:feature/my-feature
fatal: refusing to update ref with bad name 'feature/my-feature'

Expected behavior

The workflow should successfully checkout the PR regardless of branch name conflicts. The PR should be fetched and checked out to a local branch without naming collisions.

Screenshots

N/A

Workflow yml file

N/A

API Provider

[x] Anthropic First-Party API (default)
[ ] AWS Bedrock
[ ] GCP Vertex

Additional context

Background:
PR #851 was introduced to support fork PRs, which is a valuable improvement for organizations like PyTorch where 90%+ PRs come from forks.

Before #851:

  • Used git fetch origin <branch-name> - only works for same-repo PRs
  • Fork PR branches don't exist in the base repo's origin, causing fetch failures

After #851:

  • Uses GitHub's refs/pull/NUMBER/head which exists for all PRs (both same-repo and fork)
  • Successfully enables fork PR support

Root cause:
The new implementation uses git fetch origin pull/${number}/head:${branchName}, where :${branchName} creates a local branch with the PR's original branch name. This avoids detached HEAD state but introduces naming collisions when:

  • A local branch with the same name already exists
  • The workflow is currently checked out to that branch
  • The base repo has a remote branch with the same name

The issue is a trade-off: while #851 solved the fork PR problem, it created a new branch naming conflict problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2Non-showstopper bug or popular feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions