How to use the fork of a repository with Composer
Last updated: 2020-09-16 :: Published: 2015-08-10 :: [ history ]You can also subscribe to the RSS or Atom feed, or follow me on Twitter.
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 😉
You can also subscribe to the RSS or Atom feed, or follow me on Twitter.