在以下两个 StackOverflow 问题中,接受的答案描述了在分叉存储库、修改原始存储库,然后要将主分支所做的更改合并回的情况下,如何合并分叉存储库中的更改你的分叉仓库。
但是,我不清楚你如何保留您分叉的原始存储库中的非主分支是最新的。例如,当我最初分叉bitprophet的fabric存储库时,它包含以下分支:
- master
- 0.9
- 0.9-doc- rewrite(不再存在)
- path-and-#24(不再存在)
最后两个分支不再存在,现在有一个新分支flexible-task-declarations
。我已经获取、合并并推送了 master 分支,以便 master、origin/master 和upstream/master 都具有相同的 SHA1 哈希值并指向相同的 git 快照。但是,我不确定如何删除不再存在的分支并更新新分支,以便我的分支是最新的。我是否需要跟踪每个上游分支,然后单独获取、合并和推送每个分支,还是有更好的方法?
In both of the following StackOverflow questions, the accepted answer describes how to merge changes from a forked repository in the situation where you fork a repo, the original repo is modified, and then you want to merge the changes made to the master branch back into your forked repo.
However, I'm not clear on how you keep up to date on the non-master branches in the original repo that you forked. For instance, when I originally forked bitprophet's fabric repository, it contained the following branches:
- master
- 0.9
- 0.9-doc-rewrite (no longer exists)
- path-and-#24 (no longer exists)
The last two branches no longer exist, and now there is a new branch flexible-task-declarations
. I have fetched, merged, and pushed my master branch, so that master, origin/master, and upstream/master all have the same SHA1 hash and point to the same git snapshot. However, I'm not sure how to remove the branches that no longer exist and update the new branches so that my fork is up to date. Do I need to track each upstream branch and then fetch, merge, and push each branch individually, or is there a better way?
发布评论
评论(3)
场景 1:删除不再存在的分支
要删除不再存在的分支,我按照 StackOverflow 问题 如何通过发出以下命令删除本地和 Github 中的 Git 分支? :
场景2:合并现有非主分支中的更改
为了使upstream/0.9分支保持最新,我执行了以下操作:
场景3:跟踪新的非主分支
不确定这是最好的处理方式,但这就是我所做的:
确认所有分支都处于同一提交:
这将显示所有分支(本地和远程)并显示最新的提交消息和 SHA1 哈希值。
网络研究可能会揭示处理场景 3 的更好方法
Django 的 Github 工作流程
Django 项目有关于如何在 Github 上协作的说明,该说明使用了以下内容处理分叉和拉入上游更改的标准方法。
不同的初始分叉配置
Long Nguyen 的客座帖子,标题为 为 GitHub 上的开源项目设置 Git 存储库 描述了一种有趣的方法来设置您已分叉的 Github 存储库。根据本文,此方法的目标是:
Scenario 1: Deleting the branches that no longer exist
To delete the branches that no longer exist, I followed the instructions in the answer to StackOverflow question How do I delete a Git branch both locally and in Github? by issuing the following commands:
Scenario 2: Merging changes in an existing non-master branch
To get the upstream/0.9 branch up to date, I did the following:
Scenario 3: Tracking the new non-master branches
Not sure that this is the best way to handle, but here's what I did:
To confirm that all branches are at the same commit:
This will show all branches—local and remote—and show the most recent commit message and SHA1 hash.
Web research that may shed light on a better method for handling scenario 3
Django's Github Workflow
The Django project has instructions on how to Collaborate on Github which uses what appears to be the standard way to handle forking and pulling in upstream changes.
Different Initial Fork Configuration
Long Nguyen's guest post entitled Setting up your Git repositories for open source projects at GitHub on Michael Hartl's blog describes an interesting method to setup a Github repository that you've forked. The goals of this method according to the article are to:
基本上,您有 3 个远程 Git 存储库,请考虑:
您可以将上游作为远程存储库添加到本地。
查看远程分支
并推送(删除)在原点存在但在上游不再存在的分支
然后
清除本地存储库上的分支(原点上不再存在,因为您刚刚删除了它们
)存在于原点和上游的分支也需要同步(在将工作推送到原点之前,在上游的分支之上重新调整本地分支可能是向上游发出非常简单的拉取请求的好方法:bitprophet 只会快进合并以包含您的工作)
我不知道您是否可以有一个更简单的过程/命令/脚本来同步两个远程存储库。
Basically, you have 3 remote Git repo ton consider:
You could add upstream as a remote repo to your local.
look at the remote branches
and push (delete) the ones which exists at origin but no longer exist at upstream
Then
to clear the branches on your local repo (which do not exist anymore on origin, since you just deleted them)
The branches which do exist both in origin and upstream need to be synchronized as well (rebasing your local branches on top of those from upstream before pushing your work to origin can be a good way to make very easy pull request to upstream: bitprophet would only have fast-forward merge to do to include your work)
I do not know if you could have a more simple process/command/script to synchronize two distant repositories.
我在寻找如何干净利落地执行已接受答案中的场景 3 时遇到了这个答案。经过一番挖掘后,使用 git 1.8,您可以执行以下操作:
I came across this answer while looking how to do Scenario 3 in the accepted answer cleanly. After some digging around, with git 1.8 you can do the following: