Search code examples
gitgithubgit-pushgit-remotepull-request

Git push without creating new branch


I have 2 remote branches remote/master and remote/feature, and a local branch foo that was set up to track remote/feature.

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

I want to push my commits to feature and issue a PR against master.

When I push my commits to remote, a new remote branch named foo is created automatically (which I don't want to).

$ 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)

In attempt to not creating new branch, I try this:

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

This time, new branch is not created but the exiting PR is updated with my commits, which is also not what I want.

How can I push to remote and create a new PR without creating a new branch or updating existing PR?


Solution

  • If there is already an active pull request from your remote feature branch to master, pushing new commits to feature will update the existing pull request.

    This is by design; 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.

    The only way to submit a new pull request is to do it from a different branch.