`pr create` push detection should work in repositories that are tracking only a single branch
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_TOKENenvironment variable. - The command succeeds if the
--headoption is used.
Thanks for reporting!
- After you push the branch, is the remote-tracking branch created? Check with
cat .git/refs/remotes/origin/<branch-name> - Do you have multiple git remotes in this repository?
- Is your gh up-to-date?
@mislav
- I can't check now, but I assume that the remote tracking branch is created when using
git pushwith the-uoption - No.
- It's whatever version is currently on the Github Actions
ubuntu-latest(18.04.5) image (According to this page, version 1.5.0).
@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.
@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.
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
Perhaps worth mentioning, Since git release 1.8.3.2, using --depth ignores remote branches unless --no-single-branch is also specified.