title: git: ignore source in production branch and minified files in development
body: <p>I cannot find a sensible solution for as I reckon a very simple task. Consider I have some <code>source</code> directory in my project, where all source files are. In development mode, I change source files, and Gulp minifies them into <code>.min.js</code> and <code>.min.css</code> and puts them into <code>public</code> directory (to clarify, I'm building a node.js app).</p>
  
  <p>Now, I have two branches: <code>master</code> for production and <code>development</code> for development.</p>
  
  <h2>.gitignore file on <code>master</code> branch</h2>
  
  <pre><code>.DS_Store
  node_modules
  source
  ...
  </code></pre>
  
  <h2>.gitignore file on <code>development</code> branch</h2>
  
  <pre><code>.DS_Store
  node_modules
  public/javascript
  public/stylesheets
  ...
  </code></pre>
  
  <p>The behavior I want to get: 1) ignore minified files for development (they are assembled and minified every time I change the code anyway), but keep source; 2) ignore source files for production (since I don't want to have them when I <code>$ git pull</code> it into the production environment), but keep minified.</p>
  
  <p>For some reason when I switch back and forth from <code>master</code> to <code>development</code>, git completely removes some files and breaks everything. For instance, it wipes all contents of every module in <code>node_modules</code>, forcing me to do <code>$ rm -rf node_modules &amp;&amp; npm install</code> every time I switch branches.</p>
  
  <p>Any help is very much appreciated.</p>
  
  <hr>
  
  <p>The problem is also described here: <a href="https://stackoverflow.com/questions/1836742/using-git-how-do-i-ignore-a-file-in-one-branch-but-have-it-committed-in-another">Using git, how do I ignore a file in one branch but have it committed in another branch?</a>, but with no working solutions.</p>