Cheat Sheets · Git Cheat Sheet · Git Sync Fork with Upstream — Step-by-Step
Git Sync Fork with Upstream — Step-by-Step
git remote add upstream <original-repo-url>1. Add upstream remote (one-time setup)
git fetch upstream2. Fetch latest commits and branches from upstream
git checkout main && git merge upstream/main3. Fast-forward your local main branch
git push origin main4. Push synchronized changes to your GitHub fork
Complete fork sync sequence
| Command | Step |
|---|---|
git remote add upstream <original-repo-url> | 1. Add upstream remote (one-time setup) |
git fetch upstream | 2. Fetch latest commits and branches from upstream |
git checkout main && git merge upstream/main | 3. Fast-forward your local main branch |
git push origin main | 4. Push synchronized changes to your GitHub fork |
Keeping a fork updated prevents merge conflicts when you submit pull requests to the original open-source repository.
Related Git recipes
FAQ
How do I verify if upstream is configured?
Run git remote -v. You should see both origin (your fork) and upstream (original repo).
Should I merge or rebase against upstream?
For main, merge (or fast-forward) is standard. For your feature branches, rebase against upstream/main to keep clean linear history.
Can I use the GitHub UI "Sync fork" button?
Yes, the GitHub UI button does the same fast-forward merge on the remote side. Afterwards, run git pull locally.
Stop memorizing — build it interactively
Build remote workflows in the Git BuilderFull reference: Git Cheat Sheet