Add a Git repository as a package using Composer for PHP

There isn’t much documentation on how to setup PHP libraries using Composer that are not in Packagist; one way to do this is as a package. If you specify the version number of the library (or other code) that you want you can fetch them from zip files, Subversion or Git. This way you don’t need to add any Composer files (such as composer.json) to the library itself, which is handy if they don’t support Composer yet.

    "name": "andrewkirkpatrick/sample",
    "description": "Sample project",
    "homepage": "",
    "repositories": [{
	"type": "package",
	"package": {
	    "name": "andrewkirkpatrick/library",
	    "version": "0.1.0",
	    "source": {
                "url": "",
	        "type": "git",
		"reference": "0.1.0"
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.*",
	"andrewkirkpatrick/library": "0.1.*"

If you are using Git as above, the version number should correspond to a tag of the same name. Composer will try to clone using that tag.

Drawbacks of this is that you have to specify an exact version in composer.json and if you are updating the library also (unlike say using a specific version of WordPress) then you’ll need to tag every library update and update the project’s composer.json to get the changes.


Leave a Reply to Sven Müller Cancel reply