
If you work alone, there’s nothing to do at this point, you can skip to the next step. If you have already pushed a commit containing a secret, or just discovered a secret in your existing history, things get more complicated if there are other people working on this branch. When we’re done cleaning things up, you can use git stash pop to restore your work. This sets your work aside in a temporary “stash” so that we can work with the git repository without losing anything you haven’t committed yet. Please don’t push it up just yet.If you have any uncommited work, we can use git stash to save it.
#Git undo last push how to#
Now, let’s consider different scenarios to see how to clean things up.

Need to quickly see what scenario applies to you?Ĭheck out our cheatsheet flow chart below Download the git history cheatsheet If you don’t know how to revoke it, you will need help from the owner of the resource protected by the secret. How to revoke a secret is going to vary quite a lot depending on what the secret protects. And in more complicated cases, we can use git-filter-repo, a tool recommended by the core git developers for deep cleaning an entire repository.įirst and foremost, if there is reason to think that the secret has escaped into the world, and you can revoke the secret, do so. Thankfully, for simpler cases, git provides commands that make cleaning things up easy. Because git keeps a history of everything, it’s not often enough to simply remove the secret or file, commit, and push: we might need to do a bit of deep cleaning.

But mistakes were made, and now you need to figure out how to excise confidential information from your repo. You know that adding secrets to your git repository (even a private one) is a bad idea, because doing so risks exposing confidential information to the world.
