GIT · Linux · MAC

Sync/Update a forked GIT Repo

Statement : While working on a project, we need to fork a GIT repo for the local development and there we make some changes in our local branch. Once the changes are done, we raise a PR against upstream repo. Most of the times, out local forked repo goes out of sync, so keep the repo updated we need some mechanism to do the same.

Solution :

  • First, we need to define the upstream repo.
git remote add upstream https://github.com/repo.git
  • Now, fetch the upstream repo.
git fetch upstream
  • Then, check out your forked master branch.
git checkout master
  • Merge or rebase your local master branch with the upstream’s master.
git merge upstream/master
            OR
git rebase upstream/master
  • Finally, push your changes into your master branch.
git push origin master --force

Hope it helps you to sync/update your forked repo with your upstream master. 🙂

Leave a comment