Merging between forks in GitHub

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.

Leave a Comment