Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you check in your compiled assets to Git?

So I've been having this discussion with some co-workers and I'd like some other people to weigh in on this. I'm curious to see what other developers are doing.

What I like to do is ignore my entire build/assets folder from the repo. This folder contains my compiled CSS, Javascript, and compressed images. I think only the source files should be checked in. I find it annoying that every time I make a change to a stylesheet or JS file, I have to check in the source file AND the new compiled version. This also introduces merge conflicts and other issues when you have multiple people working on the project. I like to keep the repo nice and light and then have the developer build the project locally to get set up. Or when you deploy, have the server build out the project.

This is somewhat an issue, because my co-workers use Git as the deploy process. So when you want to deploy, you check your code into git, push it to the remote repo, and then you SSH into the server and do a git fetch && git pull. This means that ALL of the website files have to live in the repo. So I now have to check in my assets folder.

How do you guys handle this? I'm using bedrock-ansible for a Wordpress site, and there's an option to run some commands right before it deploys, so I configured it to run npm install && gulp build and build out the project, but the issue is that it was way too slow. The way bedrock-ansible works is that it creates a new release directory for each deployment, and it just symlinks the latest one to the current directory. So each time I deployed, it ran npm installwhen in reality, I only need those dependencies in one shared directory. There might be a way to do that with npm install --prefix install/dir but I haven't tested it out yet. I think that might introduce more issues.

For now, I had to check in all of my compiled assets to git, to get this working. But on my gulp watch task, I don't have any minification happening, but when I want to deploy, I want to run gulp build first which will minify and uglify everything - so technically I would always have to make a commit when I want to deploy the site. It's a mess. What do you think is a good way to handle this?

like image 712
Drew Avatar asked May 29 '15 19:05

Drew


1 Answers

gulp build could put all compiled files in a dist/ directory and gulp publish could push this directory to the remote. You can use git-directory-deploy for this:

$ git-directory-deploy --directory dist --branch master

Or you can manually set up a separate branch for compiled assets and push it to the remote server when deploying your website (this SO answer might help).

This way you can maintain a clean history on your development branch and not worry about merge conflicts while still using Git as a deploy process.

like image 100
eush77 Avatar answered Oct 01 '22 20:10

eush77