2

I want to sync staging branch with master using GitHub CLI tool (gh). So I am on the master branch locally and I run this command:

gh pr create -b staging -t "master -> staging"

but I receive this error:

must be on a branch named differently than "master"

I am still new to GitHub CLI and I am not sure why I need to have a branch different name.

Matt
  • 12,848
  • 2
  • 31
  • 53
Zaid Afaneh
  • 114
  • 1
  • 10

1 Answers1

2

By default, gh pr create uses the currently checked out branch as the branch containing the commits for your pull request (head). Consequently, your command tries to create a PR from master to master which is not possible.

You can use the head and base parameters to create the desired PR (merging master into staging) like this:

gh pr create --head master --base staging

If you are currently on the master branch, you can omit the head parameter:

gh pr create --base staging

Both ways result in this: result


Sidenote: In your question you are using -b staging which is short for --body staging. The correct shorthand for --base staging would be -B staging.

Matt
  • 12,848
  • 2
  • 31
  • 53
  • If the 'pr create' uses the currently checked-out branch as head, why did it work when I specified the head as master but didn't work when I was already checked out to master? – Zaid Afaneh Mar 14 '22 at 10:35
  • @ZaidAfaneh I don't think that specifying the `head` parameter actually solved your problem but the correct usage of the `--base` parameter. I just extended my answer a bit to include this. Note the difference between the shorthand for the body (`-b`) and for the base (`-B`). – Matt Mar 14 '22 at 10:57