How to synchronize branches in Git

  • 8th Mar 2025
  • 1 min read
  • • 
  • Tags: 
  • Git
  • GitHub
  • Last updated on 8th Mar 2025

As I collaborate on other users’ GitHub repositories, I often need to synchronize the main branch to retrieve the latest changes. Here’s how I do it. To keep my forked repository up-to-date, I follow these steps:

synchronize_branches

I pull the changes from the main branch of the original repository.

git pull upstream main

After pulling the changes, I push them to my forked repository to ensure it’s updated.

git push origin main

If I need to synchronize a different branch, I use:

git pull upstream other-branch

Sometimes, I want to review changes before merging them into my local branch. Here’s how I do it:

git fetch upstream
git diff main upstream/main
git merge upstream/main
git push origin main

By following these steps, I can keep my forked repository synchronized with the original, ensuring I’m always working with the most up-to-date code.