Composer: how to use your github forks

Scenario

Imagine you are using a github project in your composer file

"require": {
  "original-user/project": "dev-bugfix"
}

Now, this dependency does not do exactly what you want, so you want to change it and use your fork instead (and potentially submit a pull-request).

How to use your fork

Just add your repository into composer.json

"repositories": [
   {
     "type": "vcs",
     "url": "https://github.com/mygithub-username/project"
   }
  ]

Important: Do not change the “require” part, it must continue using original-user/project.
Run a “./composer.phar update” and composer will then download your fork (even though it echoes “installing  original-user/project” during the operation).

Go into “vendor/original-user/project” and run “git remote -v” for a double check, you’ll see the remote source “composer” that is your fork, and “origin” that is the original project. From there you can commit the changes to your fork and update it from origin (git pull origin master).

 

documentation

Composer

Loading a package from a VCS repository# There are a few use cases for this. The most common one is maintaining your own fork of a third party library. If you are using a certain library for your project and you decide to change something in the library, you will want your project to use the patched version. If the library is on GitHub (this is the case most of the time), you can simply fork it there and push your changes to your fork. After that you update the project’s composer.json. All you have to do is add your fork as a repository and update the version constraint to point to your custom branch. For version constraint naming conventions see Libraries for more information. Example assuming you patched monolog to fix a bug in the bugfix branch: