Skip to content

Conversation

@kirisame-wang
Copy link

@kirisame-wang kirisame-wang commented Feb 11, 2026

Problem

Fixes #930

PR checkout fails when the PR's branch name conflicts with existing local or remote branches. This issue was introduced in #851 when adding fork PR support.

Solution

Use unique local branch names in pr-{number} format (e.g., pr-123) instead of the original branch name when checking out PRs.

Example:

# Before (fails if 'feat/my-feature' already exists)
git fetch origin pull/123/head:feat/my-feature

# After (always unique)
git fetch origin pull/123/head:pr-123

Changes

  • Modified src/github/operations/branch.ts:
    • Store original branch name for logging only
    • Use pr-{number} as local branch name for checkout
    • Add detailed logging showing the branch name mapping

Benefits

  • ✅ Guarantees uniqueness (PR numbers are unique per repo)
  • ✅ Maintains fork PR support via GitHub's pull/{number}/head refs
  • ✅ Works for both same-repo and fork PRs
  • ✅ Simple and predictable naming convention

Testing

Existing tests cover the pr-{number} format (validated as hyphenated branch names).

Verification

✅ Tested successfully on private repository:

  • Verified with a fork PR containing branch name test/claude-action-fork-fix
  • Successfully checked out as pr-{number} format
  • Logs confirm proper branch mapping and checkout process

The previous implementation used the PR's original branch name when
fetching, which could conflict with existing local or remote branches
of the same name. This caused checkout failures for PRs with common
branch names like 'main' or 'feature/xyz'.

Changes:
- Use 'pr-{number}' format for local branch names (e.g., pr-385)
- Preserve original branch name for logging purposes
- Add detailed logging showing original -> local branch mapping

This ensures uniqueness since PR numbers are unique per repository,
while maintaining support for both same-repo and fork PRs via
GitHub's pull/{number}/head refs.

Fixes the issue introduced in anthropics#851 where fork PR support was added.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PR checkout fails due to branch name collision after #851

1 participant