我们要求班上的学生使用github来保存他们所有的课程项目代码。每个学生都创建了他的回购。 (我想我应该创建回购并创建团队,这是我的错误)。然后,我在我的组织下分配了每个回购。
我认为当学生更新原始回购时,我可以简单地提取更改。我认为我对拉力如何运作的理解是错误的。
在下图中,我可以看到学生已经用一些新文件更新了他的回购,但有没有办法可以简单地更新我已经分叉的回购?
答案 0 :(得分:9)
假设您有一个中央存储库,您需要更新您的分叉存储库,只需add the source repository as a remote,然后使用标准git pull。然后,您可以将这些更改推送到分叉仓库。
有两种方法可以轻松更新您的分叉:
将上游回购合并到您自己的...
# 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
或者,你可以使用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