Gihub CLI 错误:必须位于名称与“master”不同的分支上
我想使用 GitHub CLI 工具 (gh
) 将 staging 分支与 master 同步。因此,我在本地的 master 分支上运行此命令:
gh pr create -b staging -t "master -> staging"
但收到此错误:
必须位于名称与“master”不同的分支上
我对 GitHub CLI 仍然很陌生,我不确定为什么需要有一个不同名称的分支。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
gh pr create
使用当前签出的分支作为包含拉取请求提交的分支 (head
)。因此,您的命令尝试创建从 master 到 master 的 PR,这是不可能的。您可以使用
head
和base
参数创建所需的 PR(将 master 合并到 staging),如下所示:如果您当前位于
master
分支,则可以省略head
参数:两种方式都会导致以下结果:

旁注:在您的问题中,您使用的是
-b staging
,它是--body staging
的缩写。--base staging
的正确简写是-B staging
。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
andbase
parameters to create the desired PR (merging master into staging) like this:If you are currently on the
master
branch, you can omit thehead
parameter:Both ways result in this:

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
.