You abandoned an old branch's approach, but want Git to record it as merged so it never resurfaces. What do you do?
AdvancedScenarioBranching and Merging Workflows
Answer
Situation read → You want ancestry without content: a merge that keeps our tree unchanged.
What I'd do →
- On
main:git merge -s ours old-approach -m "Mark old-approach as merged; superseded". - The result tree equals
main's, butold-approachcommits are now ancestors. - Future merges of that branch bring in only new commits.
Why → -s ours is a strategy that ignores the other side's content entirely. It is different from -X ours, which only prefers our side in conflicts.
Interview tip → Use sparingly; it hides discarded work. Document the reason in the message.
More on Branching and Merging Workflows
You run `git pull` and Git stops with a merge conflict in `app.py`. What do you do?BeginnerYour feature branch is three weeks old and `main` has moved a lot. Merge `main` in, or rebase onto it?IntermediateThe 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?Beginner