Include a composer package as a git repository

Sometimes, you want to see how a composer package affects the including project as you make changes. But making changes to the package, committing, pushing and then pulling down the updated package can be a painful process. Luckily, composer allows us to specify that we’d like to pull down the full repository for specific packages. We are then able to modify this repo and see our changes instantly before committing anything.

To do this we need to add two bits of code to our composer.json file. First of all we need to add the project we want to include to the require section of the file. Usually this is in the format "vendor/package" : "version". You can specify a specific branch by using dev-branchname as the version, so if we wanted to use the master branch, we could use dev-master. You can read more on require in the composer documentation.

Now that we are including the correct branch of the project, we need to tell composer to clone the github / bitbucket / whatever repo inside our vendor folder. This is done in the repositories section of the composer.json file.

The code we need to add is pretty self explanatory:

  "repositories": [
      "type": "git",
      "url": "[email protected]:username/repo.git"

Once you’ve done this, you can open your vendor/vendorname/packagename project in your IDE, edit it as you need and commit any changes to be pushed back to the repository.

comments powered by Disqus