32

How do you pull changes from the parent of a fork in Git, specifically in a github configured project?

For example, say I forked http://github.com/originaluser/originalproject into http://github.com/myuser/myproject. I don't plan on myproject on being a permanent fork, as I only want to maintain a "dev" branch to test some experimental features, and then eventually merge it back into the original project.

As such, whenever commits are made to originalproject, I want to be able to pull them down and merge them with myproject. However, I also want to be able to push changes up into myproject, but not yet immediately create a pull request to get them merged into originalproject until my branch is complete and tested. What's the best way to do this?

Edit: By default, when I create a local checkout/fork of my github fork for local development, and then push/pull changes up, these changes only effect my personal fork. I never get changes from the original project. How do I fix that?

Sorry for any incorrect git terminology.

Cerin
  • 60,957
  • 96
  • 316
  • 522

2 Answers2

50

Expanding on other answers, these are the steps I took on a fork I had of tsc-watch:

git remote add upstream https://github.com/gilamran/tsc-watch.git
git fetch upstream
git merge upstream/master
git push

Explained:

  1. adding the remote server as upstream (alias)
  2. fetch all changes from the upstream remote
  3. merge changes from upstream/master branch into my current branch
  4. push all changes to GitHub
Frank Orellana
  • 1,820
  • 1
  • 22
  • 29
9

You can add the parent repository (upstream) as another remote branch. Something like

git remote add upstream ...

and then you can just git fetch to see any changes and then rebase/merge... whatever.

Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
Jiří Pospíšil
  • 14,296
  • 2
  • 41
  • 52
  • 3
    Clone your fork (myuser/myproject), cd into it and then type git remote add upstream https://github.com/originaluser/originalproject.git and then type git fetch. After that you should have master (your local master branch), origin/master (your remove master branch) and finally upstream/master (originalproject's master) from which you can pull changes into your repository. – Jiří Pospíšil Dec 11 '12 at 21:15
  • 1
    You also need to specify the new remote on `git fetch`, otherwise it doesn't fetch it: `git fetch upstream` does the trick. – Kev Apr 19 '17 at 08:34