2012-03-20 75 views
0

我们要求我们班的学生使用github来保留所有课程项目代码。每个学生创建他的回购。 (我想我应该创建回购和创建团队,这是我的错误)。然后我在我的组织下分配了这些回购协议。从原始回购拉动更新

我认为我可以简单地将变化拉到学生更新其原始回购时。我认为我理解拉队的工作方式是错误的。

在下面的图片中,我可以看到那个学生用一些新文件更新了他的回购,但是有什么办法可以简单地更新我分叉的回购吗?

enter image description here

+0

可能重复[?如何更新GitHub的分叉库(http://stackoverflow.com/questions/7244321/how-to-update- github-fork-repository) – Nate 2012-03-20 19:55:07

回答

9

假设你有一个中央存储库,你需要更新你的分叉回购,简单地add the source repository as a remote然后使用标准git pull。然后,您可以将这些更改推送到您的分叉回购。

有两个选项可以轻松地更新你的叉:

选项1

合并上游回购到自己的...

# Add the remote, call it "upstream": 

git remote add upstream git://github.com/whoever/whatever.git 

# Make sure that you're on your master branch: 

git checkout master 

# Merge the upstream master branch to your master branch 

git pull upstream master 

# Now push your changes to your forked repository on github 

git push origin master 

选项2:

另外,你可以用rebase来更新你的货叉...

# Add the remote, call it "upstream": 

git remote add upstream git://github.com/whoever/whatever.git 

# Fetch all the branches of that remote into remote-tracking branches, 
# such as upstream/master: 

git fetch upstream 

# Make sure that you're on your master branch: 

git checkout master 

# Rewrite your master branch so that any commits of yours that 
# aren't already in upstream/master are replayed on top of that 
# other branch: 

git rebase upstream/master 

# Now push your changes to your forked repo on github... 

git push origin master 

Github上有详细的文档上与分叉库工作:Github: Fork a Repo

+0

看起来不错,虽然有些步骤和文本可能是不必要的。 'git pull source'应该足够了,取指就会自动完成。 'git push'应该推送到您的仓库(假设它正常检出或启用'tracking'设置) – harningt 2012-03-20 20:35:33

+0

您描述选项1 ...如果您在叉上完成了更改,则必须使用选项2为了不丢失你的提交 – klaustopher 2012-03-20 21:29:02

+0

@klaustopher,选项1不会覆盖你的提交,除非有传入的工作会改变它。 (在这种情况下,你必须解决一些冲突)这取决于你想要做什么。这两个选项都是安全的,但如果您希望将提交应用于传入提交之上,则可以使用rebase。关于该主题的更深入的讨论(问答):http://stackoverflow.com/questions/457927/git-workflow-and-rebase-vs-merge-questions – 2012-03-20 21:39:22