How to undo a git push
Sankeeth Sriranganathan
Posted on March 6, 2024
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
- Use
git log
to view your commit history and find the bad commit (like a rewind button for your code history). - 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 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.