Skip to content

Instantly share code, notes, and snippets.

@dtuite
Last active December 12, 2015 09:49
Show Gist options
  • Save dtuite/4754105 to your computer and use it in GitHub Desktop.
Save dtuite/4754105 to your computer and use it in GitHub Desktop.
Git Tips from the Pros Taken from: http://goo.gl/jzuub

Checkout your last branch

git checkout -

Deleting Merged Branches

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

Delete a String from Entire History

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment