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 →
- If only I use the branch:
git fetch origin && git rebase origin/main, resolving conflicts commit by commit. - If others share it:
git merge origin/maininstead, so nobody has to reset. - Push with
git push --force-with-leaseafter a rebase. - 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.
More on Branching and Merging Workflows
You run `git pull` and Git stops with a merge conflict in `app.py`. What do you do?BeginnerThe team argues about fast-forward merges versus merge commits on `main`. How do you settle it?BeginnerA teammate branched from the wrong base, and their PR shows 40 unrelated commits. How do you fix it?IntermediateBefore merging, you want to see exactly what the feature branch adds compared to `main`. Which commands?BeginnerHalfway through a merge you realise you pulled the wrong branch. How do you back out?BeginnerYou keep resolving the same conflicts again and again while rebasing a long-lived branch. How do you stop?Intermediate