To use your forked version of a PHP package (hosted on GitHub) instead of the original one from Packagist in your project via Composer, you need to update your composer.json file with a few changes.
✅ Goal:
Tell Composer to install your forked version (github.com/yourname/package) instead of the original (vendor/originalpackage), and always pull the latest commit (dev-master or any branch you're using).
🛠️ Step-by-step Instructions
1. Add a custom repository
In your project's composer.json, add a repositories section that points to your GitHub fork:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/yourname/your-forked-repo"
}
]
}
Composer will now look at your fork before falling back to Packagist.
🔁 If your fork has the same name as the original package (e.g., vendor/name), Composer should replace it automatically.
2. Require your fork with dev-master (or another branch)
Update the require line for that package like this:
{
"require": {
"originalvendor/theirpackage": "dev-master"
}
}
Even though the package is named originalvendor/theirpackage, Composer will find it in your fork because you added the repositories entry above.
💡 Composer uses the VCS URL you provided to fetch the code instead of the original Packagist version.
3. (Optional) Use a specific branch or commit hash
If you're not using master or want a specific branch:
{
"require": {
"originalvendor/theirpackage": "dev-your-branch-name"
}
}
Or even a specific commit (rarely needed):
{
"require": {
"originalvendor/theirpackage": "dev-master#abc1234567890"
}
}
🧪 Example composer.json Snippet
Here’s a full example snippet for clarity:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/yourname/your-forked-repo"
}
],
"require": {
"originalvendor/theirpackage": "dev-master"
}
}
🚀 Final Step: Update Composer
Now run:
composer update originalvendor/theirpackage
Or to force reinstall:
composer remove originalvendor/theirpackage
composer require originalvendor/theirpackage:dev-master
📌 Notes
-
Composer caches repositories — if you push new changes and don't see them, try:
composer clear-cache
composer update --prefer-source
-
You can also use composer config repositories directly in CLI instead of editing JSON manually.
Let me know if you want help turning your fork into a separate standalone package (e.g., under your own vendor name).