Open In App

How to Update or Sync a Forked Repository on GitHub?

Last Updated : 05 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When you fork a repository on GitHub, you basically make a copy of the original repository and keep it under your own account. As time goes on, the original repository (known as the "upstream" repository) might receive updates, and it's important to keep your fork up to date with these changes. This way, you can contribute effectively and avoid any conflicts.

Using the GitHub Web Interface

This is the simplest method, involving just a few clicks on the GitHub website.

Step 1: Go to your GitHub account and open the forked repository.

fork
fork repo

Step 2: On GitHub, navigate to the main page of the forked repository that you want to sync with the upstream repository.

Step 3: Above the list of files, select the Sync fork dropdown menu.

sync
Review the details about the commits from the upstream repository, then click Update branch.

Using Command Line

This approach provides more control and is preferred by developers comfortable with the command line.

Step 1: Clone Your Forked Repository (if not already cloned)

   git clone https://github.com/your-username/your-fork.git   
cd your-fork
forkgit

Step 2: Add the original repository as a remote called `upstream`

git remote add upstream https://github.com/original-owner/original-repo.git

Step 3: Fetch Upstream Changes

git fetch upstream
fetchupstream

Step 4: Merge Upstream Changes into Your Fork

  • Switch to the main branch (usually `main` or `master`).
   git checkout master
  • Merge the upstream changes into your local repository.
   git merge upstream/master
merge

Step 5: Push the Updates to Your GitHub Fork

   git push origin main
push
Pushing the Updates to GitHub Fork

Using GitHub Desktop

For those who prefer a graphical user interface, GitHub Desktop offers an intuitive way to manage repositories.

Step 1: Open GitHub Desktop and Clone Your Repository (if not already cloned).

Step 2: Add the Upstream Repository :

  • Go to `Repository` > `Repository Settings`.
  • Click on `Remote` and add the upstream repository URL.
repset

Step 3: Fetch and Merge Upstream Changes :

  • Go to `Fetch origin` to fetch changes from the upstream repository.
  • After fetching, go to `Branch` > `Merge into current branch` to merge the changes.
fetchorigin
Fetch the latest changes from origin

By following these methods, you can easily keep your forked repository up-to-date with the upstream repository. Choose the approach that best fits your workflow and comfort level.


Article Tags :

Similar Reads