skip to Main Content

How do I update or sync a forked repository on GitHub?

To update or sync a forked repository on GitHub with the original repository, you can follow these steps:

  1. Configure the upstream remote: In your local repository, you need to configure the original repository as an upstream remote. Open a terminal and navigate to your repository’s directory. Use the following command, replacing <original-repo-url> with the URL of the original repository you forked from:
    git remote add upstream <original-repo-url>
  2. Fetch the latest changes: Fetch the latest changes from the original repository by executing the following command:
    git fetch upstream
  3. Switch to the main branch: Checkout the branch you want to update, typically the main branch (e.g., master or main), using the following command:
    git checkout main
  4. Merge the changes: Merge the changes from the upstream repository into your local branch by running the following command:
    git merge upstream/main

    If there are no conflicts, the changes from the original repository will be merged into your local branch.

  5. Push the changes: Finally, push the updated branch to your forked repository on GitHub to reflect the changes:
    git push origin main

Once the above steps are completed, your forked repository on GitHub will be updated with the latest changes from the original repository. You can create a pull request if you want to contribute the changes back to the original repository.

It’s worth noting that if you have made local modifications to your forked repository, you may encounter merge conflicts during the merge step. In such cases, you need to resolve the conflicts manually before proceeding with the merge.

A Self Motivated Web Developer Who Loves To Play With Codes...

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top