git - 将我的本地 git 存储库与 github 分支存储库连接起来?

标签 git github pull-request

我使用 git clone --bare $upstream 创建了我的私有(private)和本地存储库 (这里有详细How to create a git repository on my server from the github server?)

那时候,我不认为我会为最初的 github 仓库做贡献。 ($上游)
我发现 pull requests 只能从 github 存储库中获取。

所以我的问题是我如何为原始 github 存储库做贡献?

我想知道是否可以采用以下策略:

  1. I create a github fork from $upstream (the original opensource github repo)
  2. somehow teach my local repo about the new github fork(as I did git remote add)
  3. create a branch(MyWork) on my local clone, work, and push to the new github fork
  4. 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/

相关文章:

rest - 如何 : [REST] Get and Set Default Reviewers for a repository in Atlassian Stash (Bitbucket Server) programmatically using REST API

Eclipse EGit |分支差异

git - 如何将浅克隆推送到新的 repo 协议(protocol)?

Github:在 fork 的 master 上获取并重新设置 fork

git - SSL 证书拒绝尝试通过防火墙后的 HTTPS 访问 GitHub

github - 仓库的所有者可以看到克隆吗?

Github 忽略 pull 请求中的下游配置文件

Git pull 请求失败

asp.net-mvc - 如何通过 Git 将 Azure WebJob 与 .NET Core Web 应用程序一起部署?

重置后 Git 提交丢失 --hard。未被 fsck 找到,不在 reflog 中