Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using git for keeping all my sites backup here. It works very well, I can jump in and out of a expecific backup with a command.

The problem is, this is incremental. Even if I exclude a file now, it will still be there in the old revisions. This is good, but there are some big files, like sql backups, that I dont need to keep all the history.

As I backup my database everyday, in a different file name, I'm running out of space =p

How can I permanently remove old/deleted files from my git repository?

share|improve this question
Similar question here with a good link to an outside resource. – Sean Reifschneider Nov 14 '10 at 23:02
up vote 3 down vote accepted

Use git filter-branch. An example from the manpage:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
share|improve this answer
does it take a regular expression as filename? – Tiago Scolari Nov 5 '10 at 11:49
You could use something like git filter-branch --tree-filter 'find . -regex <regex> -print0 | xargs -r0 rm' HEAD for that. (I don't like -exec ;) – al. Nov 5 '10 at 11:55
oh that worked :) It didnt free as much space as I was thinking, but its better than nothing =p – Tiago Scolari Nov 5 '10 at 14:35
If repository size is what you're after, you should go through the "Checklist for Shrinking a Repository" in the git-filter-branch manpage. – al. Nov 5 '10 at 19:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.