简体   繁体   English

如何正确同步来自 github 的分叉仓库上的 master 和分支

[英]How to correctly sync the master and branches on a forked repo from github

I have forked a repo on github.我在 github 上 fork 了一个 repo。 Then I created a new branch for a feature I'm adding (lets call the branch 'my-new-feature').然后我为要添加的功能创建了一个新分支(让我们称该分支为“my-new-feature”)。 I've worked on my branch a bit and pushed all my work back to github (the 'my-new-feature' branch).我在我的分支上做了一些工作,并将我所有的工作都推回了 github('my-new-feature' 分支)。 Now, the user has made numerous changes to the upstream.现在,用户对上游进行了大量更改。

Questions:问题:

1) What is the correct way to sync my branch (as well as my forked master) with the upstream? 1)将我的分支(以及我的分叉主)与上游同步的正确方法是什么?

  • do i need to first switch to (checkout) the forked master or should I just fetch upstream (into the current branch)?我是否需要先切换到(结帐)分叉的主节点,还是应该只获取上游(进入当前分支)?
git checkout master
git fetch upstream
git merge upstream/master
  • as I understand, the above updates the forked master on my local machine.据我了解,以上更新了我本地机器上的分叉主节点。 I then need to push it to github, right?然后我需要将它推送到github,对吗?

git push origin

2) Is it possible to sync my forked master and all my branches all at once, or do I have to do it one by one? 2)是否可以一次同步我的分叉主节点和所有分支,还是必须一个一个地同步? ie after I've updated the forked master, do I need to repeat with all my branches:即在我更新了分叉的 master 之后,我是否需要对我的所有分支重复:

git checkout my-new-feature
git fetch upstream
git merge upstream/master
git push origin my-new-feature

or am I being dumb and there's a much easier way to do this?或者我是愚蠢的,有一个更简单的方法来做到这一点?

thank you谢谢你

Instead of doing any of the work of keeping origin and upstream synchronized on your machine, you could ask github to pull down the changes from upstream for you.您可以要求github为您从上游拉下更改,而不是在您的机器上执行任何保持originupstream同步的工作。 I mean, that is sort of the point of a fork.我的意思是,这有点像叉子。 The only reason to do this on your machine is if you need "manual" fork management.在您的机器上执行此操作的唯一原因是您是否需要“手动”叉管理。

If you do decide to do "manual" fork management, there is no reason to fetch and merge feature from upstream — because, by definition, upstream doesn't have it.如果决定做“手册”叉管理,没有理由来获取和合并featureupstream -因为根据定义, upstream没有它。 So, the first thing you said is the usual thing, if you don't want to do it all on github.所以,你说的第一件事是平常的事,如果你不想在github上做这一切。 Fetch upstream , merge into master , push to origin (or not, if no one is sharing it with you there is no rush after all), and now switch back to feature and proceed as if there were no upstream .获取upstream ,合并到master ,推送到origin (或者不,如果没有人与你共享它,那么毕竟不着急),现在切换回feature并继续进行,就好像没有upstream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM