Thoughts on Compiled CSS Files in Git

An ongoing discussion about build tools in the Underscores GitHub repository reminded me of something that seems to come up a few times of over the life span of a project.

CSS preprocessors, the best known being Sass and Less, have become essential resources that make managing complex stylesheets much easier.

A common issue when working on a project with other developers, is that commits that include changes to compiled CSS files will most likely result in a merge conflict. These conflicts can be caused by many different reasons, but they are often due to the use of multiple build tools all configured differently.

While you can get all the developers to use the same tools, all configured the same, that is an unrealistic picture.

This is even more problematic when working on open source projects with other people submitting pull requests.

Dealing with these issues on a daily basis can get annoying really fast. 🙂

Fortunately, this is something that can be easily “fixed” and the solution is to simply not add compiled CSS files to the repository. I’m a firm believer that Git should only be used to keep the source of a project, and that if a file is generated from source, it should not be there.

This approach might not work for all use cases, though. Some developers like the convenience of deploying to a production server every time a new commit is pushed, and if that’s your situation, you’ll need to add a build step somewhere along the way.

Ultimately, this is just a personal opinion and there are many other reasons why you would want to do the exact opposite, so pick a strategy that works for you and your team. 🙂

Note: Although I specifically talk about CSS related languages, all the above can be applied to any other languages that needs to be compiled. 🙌


By Tiago Noronha

Web Designer, Developer and Computer Geek from Coimbra, Portugal. I work for Automattic.