Use your fork in Composer

Composer is a great tool for managing external code in your project. It offers you a way to version the state of external code by using a single JSON file. In my previous post I’ve written about how to fix a bug in external code and how to get that fixed merged into the project. But there are times when you can’t wait until the original maintainer has the time to review and merge your fix.

Composer has got you covered, you can use your fork of with the fix immediately without doing many changes. When you open the composer.json file in your project you can add a reference to your fork like this:

This tells that the git repository with my fork must be considered, and takes precedence above the original repository for the package as it is mentioned explicitly. Since the package name isn’t changed all I need to do is refer to my fixing branch name under the “require” key in my composer.json file:

By prefixing my branch-name with “dev-” Composer knows it should use a branch instead of a specific version tag. Once we now run “composer update” the package ParameterHandler package will be updated with the fixed branch from my own repository. I can keep this branch until my fix has been merged by the package maintainer and than reset the code above to the original to get all the new and great updates.

When my fix isn’t merged immediately because it might require more work, I can still merge the upstream (the original repository) into my branch to get all the new good stuff which does make it into the package. After running an update I’ll again be up-to-date and have my own fix still readily available.