Interview Prep/Git & GitHub/Branching and Merging Workflows

You forked a repo and need to keep your fork's `main` in sync with upstream. How?

BeginnerScenarioBranching and Merging Workflows
Answer

Situation read → Your fork has only origin; you need the original as a second remote.

What I'd do →

  1. git remote add upstream https://github.com/ORG/REPO.git.
  2. git fetch upstream.
  3. git switch main && git merge --ff-only upstream/main (or git rebase upstream/main).
  4. git push origin main.

Or use the GitHub UI "Sync fork" button, or gh repo sync OWNER/fork.

Why → --ff-only guarantees your fork's main stays a pure mirror and fails loudly if you committed there by mistake.

Interview tip → Keep your work on topic branches and never commit to your fork's main.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows