Search code examples
gitgithubversion-controlgithub-cli

Gihub CLI Error: must be on a branch named differently than "master"


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.


Solution

  • 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.