A quick tip here, for all PHP developers out there who author packages registered on packagist.org.
.gitattributes file in the root of your github repository.
.gitattributes file allows you to configure several things, but the most important thing related to composer is the ability to not include certain files and folders into your release.
What I mean by that is the following. When composer installs your package with (that is with
--prefer-dist) it will pull down a zip file from github or whatever
cvs you’re using, and extract it. With the
.gitattributes file you can exclude files and folders to be included in that zip file by adding a line
When people are using your package, they might not be interested to download your
/tests folder, or your
.travis.yml file. Probably all they need is your
src folder and your
Here’s a sample
.gitattributes file which shows you a lot of files and folders you might want to exclude from your dist-releases.
.gitattributes file. How meta.
Useful other stuff
There’s other useful stuff you can control with the
.gitattributes file. These things are not related to composer though.
You can let git convert every single end-of-line in text based files to linefeeds (LF). This removes carriage returns (convert CRLF to LF) and makes sure you don’t get weird diffs where the only difference is an invisible character. Enable this by adding
* text=auto to your
.gitattributes file. If you want to specify a different end-of-line character on a file type basis, check the docs.
You can also control how diffs are displayed on a per file type basis using the
- More information on the .gitattributes file in the git documentation
- This discussion on reddit: I don’t need your tests in my production.