osteel's blog Web development resources

How to use the fork of a repository with Composer

Been here before?

You can also subscribe to the RSS or Atom feed, or follow me on Twitter.

Composer and GitHub

When using packages maintained by other developers, you may eventually find yourself waiting for a fix, an update, or the merge of a PR that will be available with the next release. If you can't wait, a workaround is to fork the corresponding repository, make the changes you need and then use your fork instead of the original package.

Say I want to use my own version of Guzzle – I would edit composer.json like so (osteel is my GitHub username):

{
    ...
    "repositories": [
        {
            "type": "vcs",
            "url": "git@github.com:osteel/guzzle"
        }
    ],
    "require": {
        "guzzlehttp/guzzle": "dev-master"
    }
    ...
}

This would use the master branch of my fork. If my fix were in a branch named bugfix, I would require dev-bugfix instead.

I would then run the following command:

$ composer update guzzlehttp/guzzle

It would download and use my fork instead of the original package. Done!

Just make sure to change it back to the latter once your fix is merged 😉

Enjoying the content?

You can also subscribe to the RSS or Atom feed, or follow me on Twitter.

Last updated by osteel on :: [ composer github fork repository php ]

Comments