Instantly share code, notes, and snippets.

What would you like to do?
remove sensitive item from github

Ever need to remove something sensitive from github?

Ensure you have a latest copy of the repo with the mess up first before removing a commit way back when!

1 - Copy the commit reference you like to go back to from the log:

git log

2 - Reset git to the commit reference:

 git reset <commit_ref>

3 - Stash/store the local changes from the wrong commit to use later after pushing to remote:

 git stash

4 - Push the changes to remote repository, (-f or --force):

git push -f

5 - Get back the stored changes to local repository:

git stash apply

7 - In case you have untracked/new files in the changes, you need to add them to git before committing:

git add .

6 - Add whatever extra changes you need, then commit the needed files, (or use a dot '.' instead of stating each file name, to commit all files in the local repository:

git commit -m "<new_commit_message>" <file1> <file2> ...


git commit -m "<new_commit_message>" .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment