Interview Prep/Git & GitHub/Branching and Merging Workflows

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 →

  1. git merge --abort returns the tree to the pre-merge state.
  2. Verify with git status that the working tree is clean.
  3. 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.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows