Syncing a forked repository means pulling in the latest changes from the original (“upstream”) repository so your fork doesn’t fall behind. GitHub offers three main ways to do this: the web interface’s built-in “Sync fork” button, the GitHub CLI, or the command line with Git directly. The web method is fastest for simple syncs, while the command line gives you more control, especially when conflicts come up.
Method 1: Sync Fork on GitHub.com (Easiest)
- Go to your forked repository’s main page on GitHub.
- Above the file list, click the Sync fork dropdown menu.
- Review the commits from the upstream repository that will be added.
- Click Update branch.
If the upstream changes conflict with your fork, GitHub will prompt you to open a pull request to resolve the conflicts instead of syncing directly.
Method 2: Sync Using GitHub CLI
If you have the GitHub CLI installed, you can sync from your terminal without switching context:
gh repo sync owner/repo-fork -b branch-name
If upstream changes conflict with your fork’s branch, the CLI can’t merge automatically. Add --force to overwrite your fork’s branch with the upstream version instead:
gh repo sync owner/repo-fork -b branch-name --force
Method 3: Sync via Command Line with Git
This method gives you full control and works well if you’re already comfortable with Git.
Step 1: Add the upstream remote (one-time setup)
If you haven’t already linked the original repository, add it as a remote called upstream:
git remote add upstream https://github.com/original-owner/repo.git
Step 2: Fetch the latest changes from upstream
git fetch upstream
This downloads the upstream repository’s commits without merging them yet.
Step 3: Switch to your local default branch
git checkout main
Step 4: Merge the upstream changes into your local branch
git merge upstream/main
If your local branch has no unique commits of its own, Git performs a simple fast-forward merge.
Step 5: Push the updated branch to your fork
git push origin main
Your fork on GitHub is now synchronized with the upstream repository.
Syncing Other Branches
If the project uses additional branches (like develop or a release branch), repeat the process for each one:
git checkout develop
git fetch upstream
git merge upstream/develop
git push origin develop
Using Rebase Instead of Merge
If you prefer a linear commit history without merge commits, rebase instead of merge:
git fetch upstream
git rebase upstream/main
git push origin main --force
Note that rebasing rewrites commit history, so a force push is required — be cautious if others are collaborating on your fork.
Common Mistakes to Avoid
- Forgetting to add the upstream remote first. Without it, Git has no way to know where to pull updates from — check your configured remotes with
git remote -v.
- Committing directly to your fork’s main branch. It’s best practice to keep your default branch clean for syncing, and do your own work in separate feature branches.
- Force-pushing after a rebase without checking for collaborators. If anyone else has pulled your branch, a force push after rebasing can cause them problems.
- Ignoring merge conflicts instead of resolving them. If GitHub or the CLI reports a conflict, you’ll need to resolve it manually (often via a pull request) rather than trying to force through a sync.
Join The Discussion
Keeping a fork in sync is one of those routine tasks that becomes second nature once you find a workflow that fits how you work. Do you prefer the one-click “Sync fork” button, the GitHub CLI, or handling it manually through the command line? Share your preferred method, how you handle merge conflicts when they come up, or any automation you’ve set up to keep your forks current.