Revert a commited secret from remote repository

The Mythical Engineer


To remove the last commit that contains a secret from your remote repository (GitHub, Bitbucket, etc.) and push again, you can follow these steps:

  1. First, remove the last commit locally while keeping the changes:
git reset --soft HEAD~1

This command will undo the last commit but keep the changes in your working directory.

  1. Now, remove the secret from your files and stage the changes:
# Edit the file to remove the secret
git add .

  1. Commit the changes without the secret:
git commit -m "Removed sensitive information"

  1. Force push to the remote repository:
git push origin +main

The + before the branch name in the push command forces the push, overwriting the remote history.

Replace main with your branch name if it’s different.


#development  #git  #github  #bitbucket 

Suggested Reading

  • * How to install Cursor AI IDE on Fedora Asahi Linux Arm64

    * From Chaos to Control: Using Direnv to Manage Multiple GitHub Accounts

    * How Postgres Triggers Can Simplify Your Backend Development

    * Running Rust Kernel in Deepnote

    * List of most used Key-Value stores and databases

  • Share this: