When you fork someone’s repository on GitHub, you’ll want to update your fork with any changes made to the original. There are various ways to do this. In this quick tip, Bruno describes how to update your fork via the GitHub website. Another option is to update your fork via the command line.
I often find myself having to update my fork of someone else’s repo to include the changes made to the original since the fork. In fact, we use this approach often in SitePoint’s Peer Review System as well.
Purely by accident, I’ve recently discovered a way to quickly and easily sync a fork with the original repo through the GitHub web UI, so no need to go commando (use the command line).
Note that the approach below does a merge commit, not a proper rebase. If you understand what this means, this is something that will matter to you. In a nutshell, the history looks different than when syncing via the command line as per Github docs. No real effect, but just a heads up!
Here’s a step by step guide, as applied to my out-of-date fork of Gatekeeper:
Step 1: New PR
Go to your own fork’s UI, and click the “New Pull Request” button:
This will take you to a screen not too different from this one:
Step 2: Base Switch
If the option to try “switching the base” is there, click that.
If the option isn’t there, switch the bases manually by using the provided dropdowns, and set them up so that your fork is on the left, and the original is on the right, like so:
Step 3: Send and Merge
Click the green “Create Pull Request” button. In the input fields that appear, give it a title like “Syncing from original”. Optionally, add a description.
Again, click the “Create Pull Request” button to actually send the PR. The result should be a typical PR screen:
Feel free to merge it with the “Merge Pull Request” button (and “Confirm Merge” afterwards), and you’re done!
That’s it – your fork is now in-sync with the changes made to the original, and you can start working on it without fear of conflicts.
Bruno is a blockchain developer and technical educator at the Web3 Foundation, the foundation that's building the next generation of the free people's internet. He runs two newsletters you should subscribe to if you're interested in Web3.0: Dot Leap covers ecosystem and tech development of Web3, and NFT Review covers the evolution of the non-fungible token (digital collectibles) ecosystem inside this emerging new web. His current passion project is RMRK.app, the most advanced NFT system in the world, which allows NFTs to own other NFTs, NFTs to react to emotion, NFTs to be governed democratically, and NFTs to be multiple things at once.