If you have accidentally pushed sensitive information to your repository, here’s how to remove such information:

  1. Make sure that any passwords, keys or any other sensitive information gets changed.

  2. If you are working on a branch type the following commands:

    a. git reset --hard HEAD~1

    b. git push --force-with-lease origin HEAD

git reset --hard HEAD~1 - Makes you lose all changes that are uncommitted and all files that are untracked in addition to the changes that you introduced in your last commit.

git push --force-with-lease origin HEAD - Force pushes while maintaing any other commits that have been made in addition to yours on the branch, hence --force-with-lease.