git push to the forked prj; pull request to a parent branch

允我心安 提交于 2019-12-08 06:41:02

问题


When I forked the project initially and set up my env I had this.

> git branch -a

remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/upstream/master

I do not have "push" permission to the upstream project. I must send pull requests from my fork.

A week later a new branch was created for work on a specific enhancement to upstream. The team may be working from this branch for many weeks.

remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/upstream/new-project-feature
remotes/upstream/master

What is the appropriate way for me to setup and submit code to this branch? This is what I have done. Was it the proper thing to do?

git branch new-project-feature
git checkout new-project-feature
git rebase upstream/new-project-feature
.. code changes
.. commit
git push origin HEAD:new-project-feature
.. go to github and send the pull request.

How does the parent project know to merge the pull request to its new-project-feature branch?


回答1:


The idea behind a pull-request is:

  • you work on a small enhancement that you would like to see merged into the upstream branch
  • you push that enhancement to your fork (origin), and make the pull request from there

BUT:

You should make that enhancement in a dedicated branch, not in the target branch.
That means, not in master or in new-project-feature: those are "target" branches which, in your fork, are there to mirror the upstream repo, to "remote track" upstream/master or upstream/new-project-feature.

So you should make one or several branches, each one for a small change you want to contribute to new-project-feature, push that one little branch "small_change", and make a pull request to upstream/new-project-feature.

You can regularly pull upstream, updating your local new-project-feature with the latest of upstream/new-project-feature.
You can then rebase your "small_changes" branch on top of the updated new-project-feature branch, and go on working on it.

Note that if new-project-feature changes in upstream after you already make your pull request from the fork, all you need to do is:

  • fetch and update locally the new-project-feature branch
  • rebase your small_change branch on top of new-project-feature
  • check that everything still works
  • git push --force origin small_change

The last forced push will automatically update your pull request: you won't have to do a second pull request.
See more at "How to do a Github pull request?".



来源:https://stackoverflow.com/questions/18520312/git-push-to-the-forked-prj-pull-request-to-a-parent-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!