title: remove all binary files recursively from git repo and commit history
body: <p>I have read a <a href="https://stackoverflow.com/questions/8740187/git-how-to-remove-file-from-historical-commit">few</a> <a href="https://stackoverflow.com/questions/9854810/cleaning-up-git-history">different</a> <a href="https://help.github.com/articles/remove-sensitive-data" rel="noreferrer">threads</a> on removing large binary files from git commit history, but my problem is just a little bit different. Hence my question here to understand and confirm the steps--</p>
  
  <p>My git repo is <code>~/foo</code>. I want to remove all *.jpg, *.png, *.mp4, *.ogv (and so on) from one of the directories inside the repo, specifically from <code>~/foo/public/data</code>.</p>
  
  <h3>Step 1. Remove the files</h3>
  
  <pre><code>~/foo/data &gt; find -E . -regex ".*\.(jpg|png|mp4|m4v|ogv|webm)" \
      -exec git filter-branch --force --index-filter \
      'git rm --cached --ignore-unmatch {}' \
      --prune-empty --tag-name-filter cat -- --all \;
  </code></pre>
  
  <h3>Step 2. Add the binary file extensions to .gitignore and commit .gitignore</h3>
  
  <pre><code>~/foo/data &gt; cd ..
  ~/foo &gt; git add .gitignore
  ~/foo &gt; git commit -m "added binary files to .gitignore"
  </code></pre>
  
  <h3>Step 3. Push everything</h3>
  
  <pre><code>~/foo &gt; git push origin master --force
  </code></pre>
  
  <p>Am I on the right track above? I want to measure twice before I cut once, so to say.</p>
  
  <p><strong>Update:</strong> Well, the above gives me the error</p>
  
  <pre><code>You need to run this command from the toplevel of the working tree.
  You need to run this command from the toplevel of the working tree.
  ..
  </code></pre>
  
  <p>So I went up the tree to the top level and re-ran the command, and it all worked.</p>