I’ve been using both Git and Sass for some time now. These two tools have had a huge positive impact on my development. The issue that arises when combining Git and Sass is when checking in compiled CSS, it is common to get conflicts with other contributors on the Git repository.
Don’t Check in Your Compiled Files
The short answer is to preventing Git conflicts from Sass compiled files is don’t check in your compiled files. This is done via your .gitignore
file and works great. You can view .gitignore file for my the Bootstrap Genesis Starter Theme at https://github.com/salcode/bootstrap-genesis/blob/master/.gitignore
Notice, the lines
js/javascript.min.js
and
css/style.min.css
,
excluding these compiled files form the Git repo.
What About People Without Sass?
The question that arises when you stop checking in your compiled files is, “What about people without Sass?” For developers who are contributing to a project, I think Sass is a fair requirement; however, if someone wants to download your project (e.g. a WordPress theme), it is unusable without Sass to compiled the css.
Making Compiled Files Available While Avoiding Conflicts
The solution is to create a branch, commit the compiled files to the branch, and then tag the branch with a release number. This allows you to create tagged releases that include the compiled files that users can download and use without doing any compilation themselves. You can see an example of this at https://github.com/salcode/bootstrap-genesis/releases. It is worth noting, the branch with the compiled files is never merged into your master branch.
Steps to Create a Tagged Release with Compiled Files
# create and switch to new branch "tag-branch" | |
git checkout -b tag-branch | |
# add compiled files | |
git add -f css/style.min.css | |
git add -f js/javascript.min.js | |
# commit with compiled files | |
git commit -m 'add compiled files' | |
# create a tag for commit that includes the compiled files | |
git tag -a v0.7 -m "Version 0.7 Stable" | |
# push the tags up to your remote repository (e.g. GitHub) | |
git push --tags | |
# switch back to the master branch | |
git checkout master | |
# delete the branch you used for your tagged commit | |
git branch -D tag-branch |
Example
Thanks to Scott González for explaining the process of creating a tag version that includes the compiled files.
Leave a Reply