How to update or sync a forked repository on GitHub?

This sneppet will guide you on how to update or sync a forked repository on GitHub. Forking a repository is a usual practice in software development process. It allows you to work on a project independently, collaborate with others and you can contribute back to original repository.

What is forking a repository on GitHub ?

When you fork a repository on GitHub, it means you are creating a new repository in your account with a copy of all files and history from the upstream/original repository. You can make your changes to the forked repository by creating new files or modifying existing files without affecting the original repository.

The following section will tell you how to bring your forked repository up-to-date with latest changes from the original/upstream repository. Please note, in order to keep your forked repository in sync with original one, you need to update or sync them periodically.

Update or Sync Forked Repository on GitHub

To update or sync forked repository on GitHub repository, you need to follow the below steps:

1. Fetch the latest changes from the original/ upstream repository by running the following git command.

git fetch <upstream repo>

Replace <upstream repo> with the name of the original repository that you forked from.

2. Checkout your master branch

git checkout master

3. Merge the latest changes from the upstream repository:

git merge <upstream repo>/master

Note, replace <upstream repo> with the name of the original repository.

Alternatively, you can also use git pull to fetch and merge the changes in one step as shown below.

git pull <upstream repo> master

4. Push the updated changes to your forked repository.

git push origin master

Note, make sure to replace origin with the name of your forked repository.

Alternative approach: GitHub’s built-in “Sync” feature

Alternatively, you can use GitHub’s built-inSyncfeature to update your forked repository. Follow the below steps

  1. Go to your forked repository on GitHub.
  2. Click on the “New pull request” button.
  3. Select the “Sync” option.
  4. Review the changes and click “Sync” to update your forked repository.

That’s all! Your forked repository should now be completely synced with the latest changes/updates from the upstream repository.

You’ll Also Like

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments