By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
A hyper-practical, zero-fluff guide for engineers who need to contribute to open-source, maintain forks, or sync changes from upstream repos—without breaking production.
A fork is your personal copy of someone else’s GitHub repository. It lives in your GitHub account, but it’s linked to the original (the upstream repo). Forks let you: - Experiment freely without affecting the original project.- Submit pull requests (PRs) to contribute back to the upstream repo.- Maintain long-term customizations (e.g., a company’s internal fork of an open-source tool).
Why this matters in production:- You’re a DevOps engineer maintaining a fork of kubernetes/kops with custom cloud provider patches. If you don’t sync upstream changes, your fork falls behind, and your team deploys outdated, insecure code.- You’re an open-source contributor fixing a bug in aws/aws-cli. If your fork is out of sync, your PR might fail CI checks due to merge conflicts.- You’re a security engineer auditing a fork of a popular library. If the upstream repo fixes a CVE, you must pull those changes into your fork—or risk deploying vulnerable code.
kubernetes/kops
aws/aws-cli
Real-world scenario:
Your team forks prometheus/prometheus to add custom metrics for your SaaS product. Six months later, the upstream repo releases a critical security patch. If you don’t sync your fork, your monitoring system is exposed to a known exploit. Worse, your PR to merge the patch fails because your fork diverged too far. Now you’re stuck manually resolving conflicts while your systems are at risk.
prometheus/prometheus
Production insight: Forks are not automatically updated. If you don’t sync, your fork becomes a stale, insecure time capsule.
? Upstream
facebook/react
Production insight: Always set the upstream remote immediately after forking. If you don’t, you’ll waste time later trying to figure out where the original repo lives.
? Remote
origin
upstream
Production insight: GitHub’s UI lets you sync forks with one click, but never rely on this for production workflows. Use the CLI to script and automate syncs.
? git fetch
git fetch
Production insight: Always fetch before merging. Blindly pulling (git pull) can overwrite your local changes.
fetch
git pull
? git merge
git merge
Production insight: Use --no-ff (no fast-forward) to preserve merge history. This makes it easier to track when upstream changes were incorporated.
--no-ff
? git rebase
git rebase
Production insight: Never rebase commits that have been pushed to a shared branch. It breaks collaboration and forces others to deal with messy history.
? Pull Request (PR)
Production insight: If your fork is out of sync, your PR will fail CI checks. Always sync before opening a PR.
? Merge Conflict
git --version
yourusername/react
git clone https://github.com/yourusername/react.git cd react
Why? You need a local copy to sync changes.
git remote add upstream https://github.com/facebook/react.git
Verify it worked:
git remote -v
Expected output:
origin https://github.com/yourusername/react.git (fetch) origin https://github.com/yourusername/react.git (push) upstream https://github.com/facebook/react.git (fetch) upstream https://github.com/facebook/react.git (push)
Production insight: If you skip this step, you’ll have to manually find the upstream repo’s URL later.
git fetch upstream
Why? This downloads the latest changes from the upstream repo without merging them.
main
git checkout main
Why? You’ll merge upstream changes into your local main branch first.
git merge upstream/main
If there are conflicts: 1. Git will mark conflicted files.2. Open the files, look for <<<<<<<, =======, and >>>>>>>.3. Resolve the conflicts manually.4. Stage the resolved files: bash git add <file> 5. Commit the merge: bash git commit -m "Merge upstream changes"
<<<<<<<
=======
>>>>>>>
bash git add <file>
bash git commit -m "Merge upstream changes"
git push origin main
Why? This updates your remote fork (on GitHub) with the synced changes.
If you have feature branches, rebase them onto the synced main:
git checkout your-feature-branch git rebase main git push origin your-feature-branch --force-with-lease
⚠️ Warning: --force-with-lease is safer than --force—it checks if others have pushed to the branch before overwriting.
--force-with-lease
--force
.env
.gitignore
bash git remote set-url origin [email protected]:yourusername/repo.git
.github/workflows/sync.yml
bash git tag -a sync-$(date +%Y%m%d) -m "Sync with upstream as of $(date)" git push origin --tags
master
bash git branch -m master main git push -u origin main
SYNC_LOG.md
v1.2.3
fatal: 'upstream' does not appear to be a git repository
git remote add upstream <URL>
git pull upstream main
Correct answer: git fetch upstream + git merge upstream/main.
Scenario: "Your PR to the upstream repo fails CI checks. What’s the most likely cause?"
Correct answer: "Your fork is behind the upstream repo. Sync it first."
Scenario: "You need to rebase your feature branch onto the latest main. What command do you use?"
git rebase main
pull
merge
rebase
Challenge:
You forked torvalds/linux (the Linux kernel) to yourusername/linux. The upstream repo just released a critical security patch. Sync your fork with upstream, then rebase your fix-scheduler-bug branch onto the synced main.
torvalds/linux
yourusername/linux
fix-scheduler-bug
Solution:
# 1. Sync main with upstream git fetch upstream git checkout main git merge upstream/main # 2. Rebase your feature branch git checkout fix-scheduler-bug git rebase main # 3. Push the rebased branch (force-with-lease to avoid overwriting others' work) git push origin fix-scheduler-bug --force-with-lease
Why it works: - fetch + merge ensures main is up to date.- rebase moves your commits on top of the latest main, avoiding merge commits.- --force-with-lease prevents overwriting others’ changes.
git clone <fork-url>
git clone https://github.com/yourusername/repo.git
git remote add upstream <url>
git remote add upstream https://github.com/original/repo.git
git checkout main && git merge upstream/main
git checkout feature && git rebase main
git push --force-with-lease
git push origin feature --force-with-lease
git tag -a sync-<date>
git tag -a sync-20240520 -m "Sync with upstream"
git push --force
gh
gh repo sync
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.