I pull in a package using Composer with this composer.json:
{
"require": {
"torophp/torophp": "dev-master",
},
}
When I run composer install
it seems to pull this package from GitHub directly.
I have created a fork of that repo on github with some small changes. Is there a way I can get composer to pull my version on GitHub instead of the original?
To update your packagesNavigate to the root of your git repo, where your composer. json file is. Run composer update (on your local machine) to update the required packages and re-generate a composer.
Composer will look in all your repositories to find the packages your project requires. By default, only the Packagist.org repository is registered in Composer. You can add more repositories to your project by declaring them in composer. json .
Publishing Composer packages from a Space Git repository Make sure your PHP library is prepared for distribution – your PHP project has a valid composer. json file. The project is stored in a Space Git repository. In Space, open the repository page and click Submit Composer Packages.
If this is your composer.json
"require": {
"torophp/torophp": "dev-master"
}
and you want to change it and use your fork instead, just add your repository into composer.json
as follows:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/your-github-username/torophp"
}
]
Important: Do not change the "require"
part, it must continue using torophp/torophp
!
After adding the "repositories"
part, run a composer update
(or composer.phar update
) and composer will then download your fork (even though it echoes "installing torophp/torophp" during the operation).
Update (18.09.2014): As mentioned by @efesaid in the comments:
If your package is published on packagist, you need to add
--prefer-source
option to force installation from VCS.
[RuntimeException] Failed to clone https://github.com/your-github-username/torophp, could not read packages from it
when trying to update), you can change the composer.json
to use the git protocol instead. To do so, change the composer.json
as follows and run composer update
again.
"repositories": [
{
"type": "git",
"url": "git://github.com/your-github-username/torophp.git"
}
]
Now go into vendor/torophp/torophp
and run git remote -v
for a double check that you use the desired source for the repository.
From there you can commit the changes to your fork and update it from origin (git pull origin master
).
Composer reference: Loading a package from a VCS repository
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With