Skip to content

Instantly share code, notes, and snippets.

@rpdelaney
Last active March 1, 2019 01:19
Show Gist options
  • Save rpdelaney/02530f43e1ec65c44cf432f3d459cea6 to your computer and use it in GitHub Desktop.
Save rpdelaney/02530f43e1ec65c44cf432f3d459cea6 to your computer and use it in GitHub Desktop.
Purge secrets from the local git repository

So you committed something you shouldn't have, like an oath token or a password. If you have not pushed yet then not all is lost.

How to purge bad commits from the local repo:

  1. Rebase out the offending commit(s)
  2. git reflog --expire-unreachable=now && git gc --prune=now

Caveats:

  • If you have pushed the commits, the cat is out of the bag. You must revoke the access credentials immediately.
  • Note that this will irrevocably remove any refs that are no longer in the tree, not only those that you just rebased out.
  • This method does not protect you from anything that can recover data from the storage media.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment