Halfway through a merge you realise you pulled the wrong branch. How do you back out?
BeginnerScenarioBranching and Merging Workflows
Answer
Situation read → The merge is still in progress (conflicts unresolved, no commit yet).
What I'd do →
git merge --abortreturns the tree to the pre-merge state.- Verify with
git statusthat the working tree is clean. - Merge the correct branch.
Why → --abort restores from ORIG_HEAD and the saved index. If you had uncommitted changes before starting the merge, Git may not restore them perfectly, so merge from a clean tree.
Interview tip → Add that you stash or commit before any merge or rebase.
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?BeginnerYou keep resolving the same conflicts again and again while rebasing a long-lived branch. How do you stop?Intermediate