How to undo a git push

sankeeth

Sankeeth Sriranganathan

Posted on March 6, 2024

How to undo a git push

Programmers, even the best, can make mistakes. They might upload unfinished code online by accident, to the wrong place, or even share private info.

Mistake made: Pushed unwanted code online

Solution: Use the git reset command to remove the unwanted changes

  1. Use git log to view your commit history and find the bad commit (like a rewind button for your code history).
  2. Run git reset --soft <commit-hash> to point your branch back to a specific commit.

Two ways to "undo" a pushed commit:

  • git reset --soft: Keeps your changes and adds them to be committed later.
  • git reset --hard: Completely removes the changes from your code.

Pushing the fix (optional):

After "undoing" the mistake, you can push the changes again using git push --hard. Be careful! This rewrites history online, so only do this if everyone agrees.

💖 💪 🙅 🚩
sankeeth
Sankeeth Sriranganathan

Posted on March 6, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024