3

I've contributed to many open source projects. Typically, as external contributors don't have write access to the repository they contribute to, the workflow is as follows:

  1. Fork the repo and clone a private copy
  2. git checkout -b feature-branch on the forked repo
  3. Push commits to this branch
  4. Open a pull request to merge local:feature-branch into remote:master

This is all fine, but I've recently ran into a problem when there is a merge conflict forcing me to merge master into my feature branch so the pull request can be accepted.

The command would typically be:

git checkout master
git pull origin master
git checkout feature-branch
git merge master

But when I go through these steps, git displays Already up-to-date., which makes sense. Because I'm in a forked version of the repo, my copy will never be able to get the recent remote changes to master.

So it looks like because I'm working on a forked copy that can't be merged, my PR is forever un-mergable.

How can I fix his problem?

Thanks so much for your help!

James Taylor
  • 6,158
  • 8
  • 48
  • 74
  • Is [this](http://stackoverflow.com/questions/3903817/pull-new-updates-from-original-github-repository-into-forked-github-repository) what you are looking for? – intboolstring Apr 05 '16 at 20:11
  • Perhaps, but I feel like this workflow is so common there should be other steps around this. – James Taylor Apr 05 '16 at 20:20

2 Answers2

1

What you'd have to do is merge master of the remote repo into your feature-branch so your branch is up-to-date with the remote master, not your own origin master.

git checkout feature-branch
git pull remote master
  • Yep, this is what I was thinking. Which is bad because I don't control the remote repo. And, worse yet, the owners of the repo don't own my fork. So the merge can never happen. – James Taylor Apr 05 '16 at 20:21
  • The fact that you can fork it in the first place means you have at least read access to it, which means you can pull from their master. `git remote add theirs git@github.com:their/repo.git` `git pull theirs master` – Nop Jiarathanakul Apr 05 '16 at 21:44
1

The command would typically be:

git checkout master
git pull origin master
git checkout feature-branch
git merge master

Well, the problem would be there on the 2nd line.

git pull origin master

The origin remote is set to your fork. If you run something like

git remote show origin

something like

* remote origin
  Fetch URL: https://github.com/YOUR-NAME/repo.git
  Push  URL: https://github.com/YOUR-NAME/repo.git
  HEAD branch: master

will show up.

That being said, you have to pull from the forked remote. Run

git remote show

which will show all of the remotes.

Checkout to your master branch and then run

git pull <the-remote-that-isnt-origin> master

where <the-remote-that-isnt-origin> is the remote that shows up that isn't origin when you run git remote show.

Now, most open source projects don't like merge commits, so I suggest rebasing.

git checkout your-branch
git rebase master
intboolstring
  • 6,891
  • 5
  • 30
  • 44