shellstreak

Undo a merge you already pushed

Careful: rewrites history

Short answer

Run git revert -m 1 --no-edit <merge-commit> and push. -m 1 tells Git to keep your branch's side and undo what the merge brought in.

If you later want the reverted branch merged for real, Git thinks it's already merged: you'll need to revert this revert first. Talk to your team before reverting shared merges.

The commands, one by one

  1. 1git revert -m 1 --no-edit HEAD

    A merge commit has two parents: 1 is the branch you merged into (main), 2 is the branch you merged. -m 1 undoes everything the merge added on top of main.

  2. 2git push

    Shares the undo with everyone.

For your own repository: If the merge isn't the latest commit, use its hash from git log --oneline.

Try it safely

You merged delivery into main and pushed, but delivery isn't launching yet.

learner@shellstreak: ~
Starting your practice shell…

Type your own commands too. Reset puts the repository back to just after the mistake.

Practise this in 5 minutes

Lesson 32, Undo the agent's mistakes, walks you through this undo and the ones around it in a safe terminal, step by step, and checks your answers.

Keep the terminal cheat sheet handy: free to print

Get the shellstreak newsletter

Short terminal and Git tips you can try in a minute, plus a heads-up when new free tools and lessons ship. It lands now and then, never a flood.

No spam, unsubscribe in one click.