Sync the Git Fork Repository to the Original Repository

Fork the original repository is a simple and easy task. But to keep the fork repository sync to the original repository is an important and critical task before submitting the pull request to the original repository.

To be honest I stuck this situation before where I have to sync the fork and original repository but I couldn’t find the solution so in the end I deleted my fork repository and re-forked the original repository again.

Finally, I found the solution and its 6 commands away to sync the repositories. Here are the simple commands

# If you haven't already added an upstream source, set your upstream
# to the fork's original source
git remote add upstream <url_to_original>

# Verify upstream is correct, you should see the URL for the upstream fetch and push
git remote -v

# Get all recent branches and commits from the upstream
git fetch upstream

# Check out your current master branch
git checkout master

# Merge the branches and commits from the upstream
git merge upstream/master

# Push the updated master to your forked remote repository
git push origin master

 

Be First to Comment

Leave a Reply

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