How to sync fork in Git
When you fork a repository on GitHub, your fork quickly falls behind the original as new commits are merged upstream.
As the creator of CoreUI with 25 years of open-source development experience, I sync contributor forks daily across multiple repositories and have refined the process to a few reliable steps.
The correct approach is to add the original repository as a remote called upstream, fetch its changes, and merge or rebase them into your local branch.
This keeps your fork current and prevents difficult merge conflicts later.
Add the upstream remote and fetch its branches.
# Add upstream remote (only needed once)
git remote add upstream https://github.com/original-owner/original-repo.git
# Verify remotes
git remote -v
# origin https://github.com/your-username/original-repo.git (fetch)
# origin https://github.com/your-username/original-repo.git (push)
# upstream https://github.com/original-owner/original-repo.git (fetch)
# upstream https://github.com/original-owner/original-repo.git (push)
The upstream remote points to the repository you forked from. You only add it once — it persists in your local clone’s .git/config.
Fetch and Merge Upstream Changes
Pull the latest upstream commits into your local main branch.
# Fetch all branches from upstream
git fetch upstream
# Switch to your local main branch
git checkout main
# Merge upstream/main into your local main
git merge upstream/main
# Push the updated main to your fork on GitHub
git push origin main
git fetch upstream downloads all commits from the upstream remote without modifying your working tree. git merge upstream/main integrates those commits into your current branch. The merge is a fast-forward when your branch has no diverging commits.
Using Rebase Instead of Merge
Keep a linear history by rebasing instead of merging.
git fetch upstream
git checkout main
git rebase upstream/main
git push origin main --force-with-lease
git rebase upstream/main replays your commits on top of the latest upstream commits, producing a linear history without merge commits. Use --force-with-lease instead of --force when pushing — it refuses the push if someone else has pushed to the same branch since you last fetched, preventing accidental overwrites.
Sync a Feature Branch
Keep a feature branch up to date with upstream changes.
# Fetch latest upstream
git fetch upstream
# Switch to your feature branch
git checkout feature/my-feature
# Rebase onto the updated upstream main
git rebase upstream/main
# Push with force-with-lease since history was rewritten
git push origin feature/my-feature --force-with-lease
Regularly rebasing your feature branch onto upstream/main means smaller, simpler rebases. Letting a branch fall far behind creates large, complex conflicts that are harder to resolve.
Syncing via GitHub UI
GitHub also offers a one-click sync button in the browser.
1. Go to your fork on github.com
2. Click "Sync fork" button (near the branch selector)
3. Click "Update branch"
The GitHub UI sync performs a merge. For most contributors this is sufficient. Use the command-line approach when you need a rebase or when you want to sync a specific branch other than the default.
Best Practice Note
This is the same workflow all CoreUI contributors follow when submitting pull requests — always sync with upstream before opening a PR to minimize conflicts. If you’re contributing to a project regularly, add syncing to your routine before starting any new work. For teams that manage many forks, consider automating sync with GitHub Actions to keep forks automatically updated on a schedule.



