title: .gitignore NuGet packages folder at any level but include .targets file at any level
body: <p>I'm trying to implement the workaround for the <a href="http://blogs.msdn.com/b/dotnet/archive/2013/06/12/nuget-package-restore-issues.aspx" rel="noreferrer">NuGet Package Restore Issues</a>.</p>
  
  <p>This involves ignoring the contents of all packages folders, at any level in the hierarchy. However, .targets files (typically in subfolders of packages folders) should not be ignored.</p>
  
  <p>For example:</p>
  
  <pre>
  .gitignore
  YourProject/
    YourProject.csproj
    packages/
      repositories.config
      Microsoft.Bcl.Build.1.0.7/
        lib/
          foo.dll
        tools/
          Microsoft.Bcl.Build.targets
  </pre>
  
  <p>Should include only files:</p>
  
  <ul>
  <li>.gitignore</li>
  <li>YourProject.csproj</li>
  <li>Microsoft.Bcl.Build.targets</li>
  </ul>
  
  <p>Windows, git version 1.8.1.msysgit.1.</p>
  
  <p>I have read several answers on StackOverflow, checked the man page, and tried numerous variants without success.</p>
  
  <p>This does not work:</p>
  
  <pre><code>packages/*
  !*.targets
  </code></pre>
  
  <p>Nor this:</p>
  
  <pre><code>packages/*
  !packages/**/*.targets
  </code></pre>
  
  <p>Nor this:</p>
  
  <pre><code>**/packages/*
  !**/packages/**/*.targets
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <ul>
  <li>This needs to work regardless of where the packages folder is at in the hierarchy.</li>
  <li>It needs to ignore files under packages, subfolders, sub-subfolders, etc.</li>
  <li>Other .gitignore lines, like <code>bin/</code>, must continue to work.</li>
  </ul>