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.
P.S. My friend is actively seeking opportunities in Product Management, Marketing Operations, or Data Analytics.
He brings strong expertise in data analytics, mathematics, and finance. Currently based in Bangalore, India, he is open to both remote and in-office opportunities.
If you're looking for a driven professional with strong analytical skills and quick learning ability, please reach out to him directly:
- Email: sachin.23@dmsiitd.org
- LinkedIn: linkedin.com/in/sachiniit
- Resume: View Resume
#development
#git
#github
#bitbucket