Skip to content

dst refspec main matches more than one when remote has a main branch and a main tag #8572

Description

@arunsathiya

Describe the bug

gh pr create fails with error: dst refspec main matches more than one when local and remote repositories have a branch and a tag with the same name. git push --set-upstream origin main succeeds in the same scenario, indicating a potential issue in how gh handles refspecs. gh version: [insert your gh version here].

Steps to reproduce the behavior

  1. In a local repo, have a branch and a tag named main.
  2. Ensure the remote (GitHub) repo also has a branch and a tag named main.
  3. Try creating a PR with gh pr create --title "Example" -F example.txt. (to an upstream remote, but for this bug report, it doesn't matter if the upstream has the same main branch and main tag conflict)
  4. Observe the error: error: dst refspec main matches more than one.

Expected vs actual behavior

Expected: gh pr create should handle the branch and tag naming conflict as gracefully as git push, creating the PR without errors.

Actual: The command fails with error: dst refspec main matches more than one.

Logs

Failure:

gh pr create --title "ci: Use GITHUB_OUTPUT envvar instead of set-output command" -F ~/Downloads/prbody.txt
? Where should we push the 'main' branch? Create a fork of microsoft/azure-schema-operator

Creating pull request for arunsathiya:main into main in microsoft/azure-schema-operator

error: dst refspec main matches more than one
error: failed to push some refs to 'github.com:arunsathiya/azure-schema-operator.git'
waiting 2 seconds before retrying...
error: dst refspec main matches more than one
error: failed to push some refs to 'github.com:arunsathiya/azure-schema-operator.git'
waiting 2 seconds before retrying...
error: dst refspec main matches more than one
error: failed to push some refs to 'github.com:arunsathiya/azure-schema-operator.git'
waiting 2 seconds before retrying...
error: dst refspec main matches more than one
error: failed to push some refs to 'github.com:arunsathiya/azure-schema-operator.git'
waiting 2 seconds before retrying...
failed to run git: exit status 1

What worked:

git push --set-upstream origin main
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 674 bytes | 674.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:arunsathiya/azure-schema-operator.git
   6b65409..8a98674  main -> main
branch 'main' set up to track 'origin/main'.


gh pr create --title "ci: Use GITHUB_OUTPUT envvar instead of set-output command" -F ~/Downloads/prbody.txt

Creating pull request for arunsathiya:main into main in microsoft/azure-schema-operator

https://github.com/microsoft/azure-schema-operator/pull/26

Activity

  1. samcoe commented on Jan 16, 2024

    @samcoe
    Contributor

    @arunsathiya That is a good catch. I tracked down the bug to this line. The refspec we are providing to git push is a bit ambiguous in this situation and we should specify it as HEAD:refs/heads/BRANCHNAME instead of HEAD:BRANCHNAME.

  2. added
    priority-3Affects a small number of users or is largely cosmetic
    gh-prrelating to the gh pr command
    and removed on Jan 16, 2024
  3. williammartin commented on Jan 29, 2024

    @williammartin
    Member

    Just for my own reference I reproduced this here:

    ➜  test-repo git:(heads/main) ✗ git checkout -b 8572-triage
    Switched to a new branch '8572-triage'
    
    ➜  test-repo git:(8572-triage) ✗ git tag 8572-triage
    
    ➜  test-repo git:(heads/8572-triage) ✗ git push --tags
    Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
    ^[[ATo https://github.com/williammartin/test-repo.git
     * [new tag]         8572-triage -> 8572-triage
    
    ➜  test-repo git:(heads/8572-triage) ✗ git push -u origin heads/8572-triage
    Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for '8572-triage' on GitHub by visiting:
    remote:      https://github.com/williammartin/test-repo/pull/new/8572-triage
    remote:
    To https://github.com/williammartin/test-repo.git
     * [new branch]      8572-triage -> 8572-triage
    branch '8572-triage' set up to track 'origin/8572-triage'.
    
    ➜  test-repo git:(heads/8572-triage) ✗ touch a && git add . && git commit -m "add triage file"
    [8572-triage ccc6ba3] add triage file
     2 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 a
     create mode 100644 example.txt
    
    ➜  test-repo git:(heads/8572-triage) gh pr create --title "Example" -F example.txt
    ? Where should we push the '8572-triage' branch? williammartin/test-repo
    
    Creating pull request for 8572-triage into main in williammartin/test-repo
    
    error: dst refspec 8572-triage matches more than one
    error: failed to push some refs to 'https://github.com/williammartin/test-repo.git'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggh-prrelating to the gh pr commandhelp wantedContributions welcomepriority-3Affects a small number of users or is largely cosmetic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions