0

We asked students in our class to use github to keep all their course project code. Each student created his repo. (I guess I should have created the repo and created teams and it was my mistake). I then forked each of those repos under my organization.

I thought that I could simple pull the changes as and when students update their original repo. I think my understanding of how the pull works is wrong.

In the following image I can see that student has updated his repo with some new documents but is there any way I can simply update the repo I have forked ?

enter image description here

Eastern Monk
  • 5,735
  • 7
  • 43
  • 60
  • possible duplicate of [How to update GitHub forked repository?](http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository) – Nate Mar 20 '12 at 19:55

1 Answers1

9

Assuming you have a central repository, you need to update your forked repo, simply add the source repository as a remote and then use a standard git pull. You can then push those changes to your forked repo.

There are two options to easily update your fork:

Option 1

Merge the upstream repo into your own...

# 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

Option 2:

Alternatively, you could use rebase to update your fork...

# 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 has detailed documentation on working with forked repositories: Github: Fork a Repo

Highway of Life
  • 18,392
  • 14
  • 43
  • 68
  • Looks good, though some steps and text may be unnecessary. A `git pull source` should be sufficient, the fetch would be automatic. A `git push` should push to your repository (assuming it was checked out normally or setup with 'tracking' enabled) – harningt Mar 20 '12 at 20:35
  • You describe option 1 ... If you have done changes on your fork, you would have to use option 2 to not lose your commits – klaustopher Mar 20 '12 at 21:29
  • @klaustopher, option 1 won't overwrite your commits unless there is incoming work that would have changed it. (In which case, you'd have to resolve some conflicts) It just depends on what you want to do. Both options are safe, but if you want your commits to be applied on top of the incoming commits, you'd use rebase. A more in-depth discussion (Q/A) on that topic: http://stackoverflow.com/questions/457927/git-workflow-and-rebase-vs-merge-questions – Highway of Life Mar 20 '12 at 21:39
  • Yeah, you're right. I was refering to @harningt's comment that some stuff was "unneecessary" in your explanation – klaustopher Mar 21 '12 at 11:57