Skip to content

AvasDream/i-pushed-credentials-for-my-companies-cloud-infra-and-now-all-our-customer-data-is-at-risk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

How to remove credentials from a git repository

# 1. Remove .env from the current commit
git rm --cached .env

# 2. Add .env to .gitignore
echo ".env" >> .gitignore
git add .gitignore
git commit -m "Add .env to .gitignore"

# 3. Rewrite history to remove .env from all commits
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch .env' \
--prune-empty --tag-name-filter cat -- --all

# 4. Clean up repository
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now --aggressive

# 5. Force-push cleaned history to GitHub
git push --force --all
git push --force --tags

# 6. Inform collaborators to reset their local repositories
# (they can use the following commands)
git fetch --all
git reset --hard origin/main

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages