title: .gitignore ignore all files then recursively allow *.foo
body: <p>There's already several questions similar to this, but none of the answers work for me.</p>
  
  <p>I want to ignore everything in the folders below my repository except files with *.foo</p>
  
  <p>(If anyone is wondering how this can be justified - I'm actually making a git repository for all my "Logic" projects - music software on the mac - but I only want to store the actual project files *.logic)</p>
  
  <p>I'm going to spell it out, so we're all on the same plate.
  Here's what I do, starting from scratch:</p>
  
  <p><strong>Setup:</strong></p>
  
  <pre><code>mkdir temp
  cd temp
  mkdir testdir
  cd testdir
  touch include.foo
  touch dontinclude.bad
  cd..
  git init
  touch .gitignore
  </code></pre>
  
  <p><strong>Paste this in to .gitignore</strong></p>
  
  <pre><code># Ignore all
  /*
  
  # But not these files...
  !.gitignore
  !*.foo
  </code></pre>
  
  <p>git status</p>
  
  <p>And the only untracked file is .gitignore</p>
  
  <p>if I typed 'git add .' - no change, only .gitignore is seen and my 2 files are ignored.</p>
  
  <p>Why doesn't this work and how can you change the procedure above to make it work?</p>
  
  <p>Here's the extremely similar question where I got the .gitignore file from.
  I'm using git --version 1.7.7 (also tried 1.7.3) - <a href="https://stackoverflow.com/questions/5876075/gitignore-to-ignore-all-files-then-recursively-allows-files-of-a-certain-type">.gitignore to ignore all files, then recursively allows files of a certain type</a></p>