Git 推送而不创建新分支

Git push without creating new branch

我有 2 个远程分支 remote/masterremote/feature,以及一个设置为跟踪 remote/feature 的本地分支 foo

[git: foo] $ git branch -u remote/feature

我想将我的提交推送到 feature 并针对 master 发布 PR。

当我将提交推送到远程时,会自动创建一个名为 foo 的新远程分支(我不想这样做)。

$ git push remote foo 
  * [new branch]     foo -> foo

$ git remote show remote
Local refs configured for 'git push':
    feature pushes to feature (up to date)
    foo     pushes to foo     (up to date)
    master  pushes to master  (up to date)

为了不创建新分支,我尝试这样做:

$ git push remote foo:feature
sha-1...sha-2 foo -> feature

这一次,没有创建新分支,但是现有的 PR 更新了我的提交,这也不是我想要的。

如何在不创建新分支或更新现有 PR 的情况下推送到远程并创建新 PR?

如果已经有从您的远程 feature 分支到 master 的活动拉取请求,将新提交推送到 feature 将更新现有的拉取请求。

这是设计使然; GitHub encourages discussion and modification of pull requests before they are merged:

You can also continue to push to your branch in light of discussion and feedback about your commits. If someone comments that you forgot to do something or if there is a bug in the code, you can fix it in your branch and push up the change. GitHub will show your new commits and any additional feedback you may receive in the unified Pull Request view.

提交新拉取请求的唯一方法是从不同的分支提交。