Revert a commited secret from remote repository
To remove the last commit that contains a secret from your remote repository (GitHub, Bitbucket, etc.) and push again, you can follow these steps:
- 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.
- Now, remove the secret from your files and stage the changes:
# Edit the file to remove the secret
git add .
- Commit the changes without the secret:
git commit -m "Removed sensitive information"
- 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