Quick Tip: Sync a Fork with the Original via GitHub’s Web UI

Share this article

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:

New Pull Request Button

This will take you to a screen not too different from this one:

PR create screen

Step 2: Base Switch

If the option to try “switching the base” is there, click that.

Switching the base option

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:

Switched sources

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.

Create a new pull request

Again, click the “Create Pull Request” button to actually send the PR. The result should be a typical PR screen:

PR screen with Merge button

Feel free to merge it with the “Merge Pull Request” button (and “Confirm Merge” afterwards), and you’re done!

Merged PR

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.

Frequently Asked Questions (FAQs) about Syncing Your Fork with the Original Repository

What does it mean to sync a fork with the original repository?

Syncing a fork with the original repository means updating your forked repository with the latest changes made in the original repository. This is important because it allows you to keep your project up-to-date with the latest developments and improvements made in the original repository. This process involves fetching the changes from the original repository and merging them into your forked repository.

Why is it necessary to sync a fork with the original repository?

It’s necessary to sync a fork with the original repository to ensure that your forked repository has the latest updates and changes made in the original repository. This is particularly important if you’re contributing to an open-source project, as it allows you to work with the most recent version of the project. It also helps to avoid conflicts when you’re ready to submit your contributions.

How often should I sync my fork with the original repository?

The frequency of syncing your fork with the original repository depends on the activity level of the original repository. If the original repository is very active with frequent updates, you might need to sync your fork more often. However, it’s generally a good practice to sync your fork before starting a new piece of work or making a contribution to the project.

Can I sync my fork with the original repository using the GitHub web interface?

No, currently GitHub does not provide a feature to sync a fork with the original repository directly from the web interface. You need to use Git commands in the command line interface (CLI) to sync your fork. This involves fetching the changes from the original repository and merging them into your forked repository.

What are the Git commands to sync a fork with the original repository?

The Git commands to sync a fork with the original repository are as follows:

1. Fetch the branches and their respective commits from the upstream repository: git fetch upstream
2. Check out your fork’s local default branch – in most cases, this is master: git checkout master
3. Merge the changes from the upstream default branch – in most cases, this is master – into your local default branch: git merge upstream/master

What if I encounter merge conflicts while syncing my fork?

Merge conflicts occur when the same part of a file has been modified in both the original repository and your forked repository, and Git is unable to determine which version to use. If you encounter merge conflicts, you’ll need to manually resolve these conflicts. Git will mark the areas in your file where conflicts have occurred, and you can decide which version to keep.

Can I undo the sync if I made a mistake?

Yes, you can undo the sync if you made a mistake. Git provides a feature called ‘git reflog’ which keeps track of all the changes made in the repository. You can use this feature to revert your repository to a previous state.

What is the difference between a fork and a clone?

A fork is a copy of a repository that allows you to freely experiment with changes without affecting the original project. A clone, on the other hand, is a copy of a repository that is downloaded onto your local machine. This allows you to work on the files locally and push changes back to the remote repository.

Can I sync my fork with the original repository if I don’t have write access to the original repository?

Yes, you can sync your fork with the original repository even if you don’t have write access to the original repository. The process of syncing your fork involves fetching the changes from the original repository and merging them into your forked repository, which does not require write access to the original repository.

What happens if the original repository is deleted after I have forked it?

If the original repository is deleted after you have forked it, your forked repository will remain intact with all the files and history. However, you will no longer be able to sync your fork with the original repository since it no longer exists.

Bruno SkvorcBruno Skvorc
View Author

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.

BrunoSforkgithubquick-tipRalphMsynchronization
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week