How to fork github repos and keep in sync with original repo

Gunjan
2 min readApr 10, 2023

--

Often we find active repos that have great license terms and can help you improve your products . The challenge is to keep a fork of a GitHub repo up to date with the master branch of the original repo.

If thats something you need do the following —

  1. Clone your forked repository to your local machine
git clone https://github.com/your-username/your-forked-repo.gi
  1. Add the original repository as a remote repository:
git remote add upstream https://github.com/original-repo-owner/original-repo.git
  1. Fetch the changes from the original repository:
git fetch upstream
  1. Switch to your local master branch:
git checkout master
  1. Merge the changes from the original repository’s master branch into your local master branch:
git merge upstream/master
  1. Push the changes to your forked repository:
git push origin master

Repeat these steps whenever you want to update your forked repository with the latest changes from the original repository.

Of course its not that simple , there are manyy challenges with keeping a forked repo with the master

  1. Merge conflicts: If the new and the original repository owner have made changes to the same code, merge conflicts when trying to merge the changes from the original repository into the forked repository need to resolved.
  2. Version compatibility issues: If you’re using a different version of as library or dependencies than the original that may have to be handled manually.
  3. Workflow differences: If you deployy elsewhere or use a different code review process or branching strategy, you may need to adjust your approach to accommodate these differences.
  4. Large or frequent updates: If the original repository is frequently updated or has a lot of changes, it may be challenging to keep up with the updates and ensure that your forked repository remains in sync. You may need to prioritize which updates to merge and when to merge them.

Summary — Forking is easy ! Maintaining the fork is hard.

--

--

Gunjan
Gunjan

No responses yet