git checkout -
Show which local branches have been merged into the current branch:
git branch --merged
Delete all merged branches:
git branch --merged | xargs git branch -d
First we need to grep a list of all commits for the string we're looking for:
git rev-list --all | xargs git grep -F '<YOUR STRING>'
Now, we'll rewrite the git history for each branch, removing the file with the sensitive data.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch <FILENAME>' --prune-empty --tag-name-filter cat -- --all
Gitignore the file and commit:
echo <FILENAME> >> .gitignore
git add .gitignore
git commit -m "Add sensitive <FILENAME> file to gitignore"
We need to force push since we're rewriting history
git push origin master --force
The compromised files still exist in your local repo, so you'll need to do a few clean-up tasks to purge them entirely.
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now