Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: ignore source in production branch and minified files in development

I cannot find a sensible solution for as I reckon a very simple task. Consider I have some source directory in my project, where all source files are. In development mode, I change source files, and Gulp minifies them into .min.js and .min.css and puts them into public directory (to clarify, I'm building a node.js app).

Now, I have two branches: master for production and development for development.

.gitignore file on master branch

.DS_Store
node_modules
source
...

.gitignore file on development branch

.DS_Store
node_modules
public/javascript
public/stylesheets
...

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 $ git pull it into the production environment), but keep minified.

For some reason when I switch back and forth from master to development, git completely removes some files and breaks everything. For instance, it wipes all contents of every module in node_modules, forcing me to do $ rm -rf node_modules && npm install every time I switch branches.

Any help is very much appreciated.


The problem is also described here: Using git, how do I ignore a file in one branch but have it committed in another branch?, but with no working solutions.

like image 329
Anton Egorov Avatar asked Apr 16 '16 09:04

Anton Egorov


People also ask

What files should be ignored in git?

Ignored files are usually build artifacts and machine generated files that can be derived from your repository source or should otherwise not be committed. Some common examples are: dependency caches, such as the contents of /node_modules or /packages. compiled code, such as .o , .

How do I add untracked files to Gitignore?

If you want to permanently ignore these files, a simple way to add them to . gitignore is: Change to the root of the git tree. git ls-files --others --exclude-standard >> .


1 Answers

It feels to me like you're asking the wrong question. The minified scripts are "build products", not "source code". Seems to me like some sort of "make install" process should create them, rather than having them in source control. But I don't work in the web space so I do not know what standard practice is.

like image 85
Mort Avatar answered Oct 22 '22 22:10

Mort