如何提交从克隆回购请求?

如何从现有的本地克隆回购提交请求?

Often, I want to look at some libraries source code from github, so I clone it. Later, I discover some issue with the code and raise it on a mailing list, often in passing. The library author says "nice find, can you send a pull request?".

答案是“没那么容易”。我还没有叉回购,我克隆了它。难道我找不到办法提交一份复制回购申请吗?

如果这个限制是正确的,那么明智的反应就是把你看到的任何东西都交出来,这样如果你想要贡献的话,你就可以做到。这样你的 github 账户就会有很多不活跃的分支。

似乎没有多少人谈论这个问题——难道我是唯一一个受到这个问题影响的人吗?

17746 次浏览

Fork the repo on GitHub, then add your fork repo as a remote to your local cloned copy:

git remote add myfork https://github.com/<myGitHubAccountName>/<repoName>.git

Then you can push to your fork:

git push myfork master

If you're doing more than just this one pull request, you can remove the origin remote and name your fork as origin:

git remote rm origin
git remote add origin https://github.com/<myGitHubAccountName>/<repoName>.git

This is typically what I do. Sometimes I add the original origin as upstream so I still have a reference to it.

If you're ok with installing another binary in your path, github has released a nice little tool called hub.

If you've cloned someone else's repo:

$ hub fork  # This creates a fork and adds your repo as a remote


$ git push YOUR_USER feature  # push the changes to your new remote


$ hub pull-request  # will open your browser

I always clone instead of fork as well and the following steps work for me:

  1. Create a new branch on your cloned repo and make the new change.
  2. Push the change to your branch as the following:

    git push origin insert_your_working_branch_name

  3. Now you should be able to find your working branch in pull request from github master.