Skip to content

pr create push detection should work in repositories that are tracking only a single branch #2979

Description

@jwodder

I have a shell script that is run as part of a GitHub Actions workflow that, on occasion, clones a repository, creates, commits to, and pushes a branch, and then creates (or at least tries to) a pull request for the branch using gh pr create. However, gh is failing with "aborted: you must first push the current branch to a remote, or use the --head flag" despite the fact that the command immediately before it is "git push -u origin "$branch_name" (tried with & without the -u option).

  • The repository is public.
  • The remote URL used to check out the repository is of the form https://x-access-token:[email protected]/$OWNER/$REPO, where the same token is also set as the $GITHUB_TOKEN environment variable.
  • The command succeeds if the --head option is used.

Activity

  1. mislav commented on Feb 16, 2021

    @mislav
    Contributor

    Thanks for reporting!

    1. After you push the branch, is the remote-tracking branch created? Check with cat .git/refs/remotes/origin/<branch-name>
    2. Do you have multiple git remotes in this repository?
    3. Is your gh up-to-date?
  2. jwodder commented on Feb 16, 2021

    @jwodder
    Author

    @mislav

    1. I can't check now, but I assume that the remote tracking branch is created when using git push with the -u option
    2. No.
    3. It's whatever version is currently on the Github Actions ubuntu-latest (18.04.5) image (According to this page, version 1.5.0).
  3. jwodder commented on Feb 16, 2021

    @jwodder
    Author

    @mislav OK, I set up this workflow as an MVCE. The run fails on your cat command, so apparently the remote tracking branch is not getting created. That is not how I understand Git to work; do you know how to fix this?

    EDIT: OK, I fixed it. The problem was due to the use of --depth 1, and adding --no-single-branch to the git clone command got rid of the error.

  4. mislav commented on Feb 17, 2021

    @mislav
    Contributor

    @jwodder Thank you for checking! I will reopen this and keep it filed as a bug report because I believe that ideally, pr create should work even in repositories that were cloned with --depth 1 or are tracking just a single branch.

  5. reopened this on Feb 17, 2021
  6. changed the title [-]`gh pr create` thinks branch hasn't been pushed to repository even though it has[/-] [+]`pr create` push detection should work in repositories that are tracking only a single branch[/+] on Feb 17, 2021
  7. added
    priority-3Affects a small number of users or is largely cosmetic
    on Feb 17, 2021
  8. vschoener commented on May 3, 2022

    @vschoener

    I just try to use the --depth 1 when creating a PR right after. It still fails :( I think it's a really important thing as some repo can be huge and take a few minutes to clone

  9. StevenACoffman commented on Jul 29, 2022

    @StevenACoffman

    Perhaps worth mentioning, Since git release 1.8.3.2, using --depth ignores remote branches unless --no-single-branch is also specified.

  10. added
    gh-prrelating to the gh pr command
    on Oct 2, 2023
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 commandpriority-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