Merging between forks in GitHub

git, github

Solution

You probably have a "remote" for each repository. You need to pull from one remote and push to the other.

If you originally cloned from your fork, that remote will be called "origin". If you haven't added it already, you'll need to add the other repository as another remote:

git remote add <shortname> git://github.com/<ownerName>/repo.git

After that's all set up, you should indeed be able to (github changed default branch from `master` to `main`, change as necessary)

git pull <shortname> master
git push origin

Remember, `git pull` is nothing more than a macro that does `git fetch` and `git merge`, in that order. You just need to fetch the list of commits from the other repository and then merge his branch into your tree. Merging should do the right thing with your commits on both branches.

GitHub, in all its perpetual awesomeness, gives you a shortcut, of course. There's a "fast-forward" button on your fork of the repository that you can use to catch your fork up if you're entirely merged into the other side.

Problem

I forked a GitHub repository. Then I pushed some changes to my fork. Then the original repository merged my changes and some others. Now, I want to merge those changes I'm missing. I tried a simple pull followed by push, but this yield my commits in duplicate. What's the best way to do it?

Original source