我使用 git clone --bare $upstream
创建了我的私有(private)和本地存储库
(这里有详细How to create a git repository on my server from the github server?)
那时候,我不认为我会为最初的 github 仓库做贡献。 ($上游)
我发现 pull requests 只能从 github 存储库中获取。
所以我的问题是我如何为原始 github 存储库做贡献?
我想知道是否可以采用以下策略:
- I create a github fork from $upstream (the original opensource github repo)
- somehow teach my local repo about the new github fork(as I did
git remote add
)- create a branch(MyWork) on my local clone, work, and push to the new github fork
- pull requests to original repo auther.
编辑
由于我的私有(private)仓库中有很多修改(提交),
我需要一种方法来进入当前 $upstream 的干净状态(upstream 的 master 没有我在我的 origin/master 中进行的本地修改,而不是在 MyWork 中)。
(这样我的 pull 请求除了分支( pull 请求)之外没有我的修改)
我该怎么做?
最佳答案
我花了很长时间才弄明白..
git 中有一个 cherry-pick
命令,非常适合我的情况。
Send a pull request on GitHub for only latest commit
基本上,
git checkout -b MyWork_for_pull_request upstream/master (make branch off upstream/master not origin/master)
git cherry-pick `sha-of-MyWork-branch's-commit` (pick out commits I want to contribute)
git push mygithub_fork MyWork_for_pull_request
然后在 github 页面中按 pull request
。
关于git - 将我的本地 git 存储库与 github 分支存储库连接起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16665292/