In the latest Laravel 5.4 version many Laravel packages needed to change their service Provider because of a breaking change. One package I was using was left behind so I thought what the heck, I’ll clone it, modify it and make a pull request with my change. Until my P.R is accepted, I’ll require my fork in my laravel project.
Easy, right? Well, not exactly so I decided to share the steps.
1st step: Fork the original project in your github account.
You just click on the Fork icon!
2nd step: Create the working branch
The easiest way to create a branch in this fork, is just to use the github button!
3rd step : Alter your composer.json
Now the tricky part! You have to add your repository as a VCS repository. You can do that by adding this code snippet in your composer.json file
As you can see, the url points to my personal github account, not the original repo. This seemed really weird to me at first, I would expect the exact oposite here.
Final step, require the fork with this command:
composer require gufy/cpanel-whm:dev-mybranchname — prefer-source
This command is the important one. Here we target the original repo BUT we point our working branch and add a ‘dev-’ in the beginning of our branch name! Composer see that we have included a VCS repository and makes the connection. Last thing is to use the ‘ — prefer-source` switch, so you can navigate to the main package folder and actually push any changes you make to your fork.
So what we have accomplished here?
We are using our fork, we are working on a specific branch so we can make a pull request any time we feel like it. All this happen in our main composer.json file, it’s not outside the scope of our app, so we can check anything we like ( like service providers for example e.t.c)
All this can be avoided of course if you just clone the fork independently, but in my case I wanted to actually use it in my project and at the same time update and make a P.R.
Don’t know if there is an easier way to do this kind of thing, if you know one please let me know!