Interview Prep/Git & GitHub/Branching and Merging Workflows

Your feature branch is three weeks old and `main` has moved a lot. Merge `main` in, or rebase onto it?

IntermediateScenarioBranching and Merging Workflows
Answer

Situation read → A private, unshared branch can be rebased safely. A branch others have pulled cannot.

What I'd do →

  1. If only I use the branch: git fetch origin && git rebase origin/main, resolving conflicts commit by commit.
  2. If others share it: git merge origin/main instead, so nobody has to reset.
  3. Push with git push --force-with-lease after a rebase.
  4. Run the full test suite on the result either way.

Why → Rebase gives a linear history that is easy to review. Merge preserves exact history and never rewrites commits others depend on.

Interview tip → The deciding factor is "has anyone else based work on these commits", not personal taste.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows