Git: ignore source in production branch and mini files in development

I cannot find a reasonable solution, because I consider it a very simple task. Think I have some sort of source directory in my project where all the source files are. In development mode, I change the source files, and Gulp overrides them in .min.js and .min.css and puts them in the public directory (to clarify, I am creating a node.js application).

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 is: 1) ignore mini files for development (they are collected and minimized every time I change the code anyway), but keep the source; 2) ignore the source files for production (since I donโ€™t want to have them when I $ git pull it in the production environment), but keep decreasing.

For some reason, when I switch back and forth from master to development , git completely deletes some files and splits everything. For example, it erases the entire contents of each module in node_modules , forcing me to do $ rm -rf node_modules && npm install every time I switch branches.

Any help is greatly appreciated.


The problem is also described here: Using git, how to ignore a file in one branch, but it was moved to another branch? but without working solutions.

+6
source share
2 answers

It seems to me that you are asking the wrong question. Minimized scripts are an assembly, not a source code. It seems to me that some kind of "make install" process should create them, and not have them in source control. But I do not work in web space, so I do not know what standard practice is.

+3
source

One solution would be to avoid switching between branches (avoiding the โ€œbreaks everythingโ€ part)

From your repo, which is currently checked as master , do (with git 2.5+) a:

 git worktree add ..\dev dev 

Using the new git worktree , you will get a second working tree associated with the cloned (only once) repo. <sh> See " Multiple Working Directories with Git? ".

In both working bodies (one for each branch), you save your .gitignore as you wish.

+1
source

All Articles