124

I have forked a repository on github some time ago, made a small change and pushed the change back to my github fork. The original repository has changed since. I would like to merge the changes from the original repository to my fork.

I am new to both git and github, and I need specific commands how to do it.

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125

4 Answers4

167
git remote add {name} {Public Clone URL}
git pull {name} master
git push

Example:

git remote add bret git://github.com/bret/watir.git
git pull bret master
git push
Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
8
git pull origin master

will do the job creating additional merge commit. If you do not have conflicts and do not want to create a rejoin (with additional 'merge' commit) for every commit that you push then rebase is more preferred. You can do it with the Git Gui+gitk. Just fetch remote with Git Gui then open history with gitk and create temporary r_master branch at remotes/origin/master fetched. Finally, call git rebase r_master in the git bash. This will place your commits on top of the remote modifications. You are ready to push and remove the r_master.

This comment suggests that there are shortcuts for this flow.

Community
  • 1
  • 1
Val
  • 1
  • 8
  • 40
  • 64
8

Syncing a fork

(from GitHub Help)

https://help.github.com/articles/syncing-a-fork

fat
  • 6,435
  • 5
  • 44
  • 70
  • Before we need to Configuring a remote for a fork: https://help.github.com/articles/configuring-a-remote-for-a-fork/ – Eric Douglas Aug 05 '15 at 10:36
8

Simply add original repo as a remote and merge your fork with it; then push merged fork to github.

There's also a ruby gem for easier github operations. You can merge upstream with one call...

Marcin Gil
  • 68,043
  • 8
  • 59
  • 60
  • 1
    I see that I forgot to add that I am new to git and github, and that I need specific commands how to do it. Thanks for github-gem, but that is overkill for me. – Željko Filipin May 15 '09 at 10:46
  • 7
    in here people must use commands/code samples. words doesn't help on stackoverflow. – holms Nov 14 '11 at 15:31