Create and use your own GitHub fork in Laravel

Let’s assume you use a Laravel package that is published on Github but you are not satisfied with some code or implementation. You want to add or change something but the original developer is not responding to your reported issues.

You can create a copy of the project in Github, change the code and use this new copy to use in your own Laravel project. We call this creating a fork. In the meantime you can upload your changes to the master project and make a pull request to the right full owner to check your code. If he finds it a welcome addition he will merge your changes into his master so everyone can benefit from it. If not, you and others can continue to use your fork. How do we create a fork, download a local copy, change the code, upload the changed to GitHub and make a pull request?

For this example I am using the GitHub Desktop client and Sublime Text with Git implementation.

  • Browse to the GitHub project you want to change;
  • Click on the Fork logo in the upper right corner;
  • GitHub will now make a new fork in your GitHub profile;
  • Download the new for to your GitHub Desktop. This will make a local copy on your computer;
  • Open the local project in your favorite code editor and start changing or adding your needs;
  • Be aware that you should split big changes in smaller pieces. So for example you want to change two classes that are separated from each other. First do the first class, commit the changes and then start with the second change;
  • After every change you can add the changed files to the repository. In sublime text I use the command Shift+Cmd+P and write Git: Add all. Now the changes are registered;
  • Next, you commit your changes to the local repository with Git: Commit. Define a short commit message about the change you added;
  • Go back to the GitHub Desktop client and now you should see a change that can be commited to the remote origin;

  • Press the button Push origin and the view your changed fork in GitHub;
  • To upload your improvements you can create a new pull request;
  • First compare the changes and also check if it is even possible to merge the changes.
  • Press the button ‘Create new pull request’ and enter a title and text where you explain what you have changed and why.

Use your fork in Laravel project

So now you have an improved piece of code but the owner is not committing your changes to the branch master. This can happen in case he left the repository. In this case you can use your fork in your project by following the next steps:

  • Open your Laravel composer.json file and locate the require part;
  • Just before this require part you can add your forked repository by adding repositories.

Code original:

"require": {
        "adman9000/laravel-binance": "dev-master",
    },

Code with forked repository:

"repositories":
    [
        {
            "type": "vcs",
            "url": "https://github.com/Xibel/laravel-binance"
        }
    ],
    "require": {
        "adman9000/laravel-binance": "dev-master",
    },
  • To finish we need to update composer so we can pull your new code into your Laravel project:
composer update
  • If you want a complete refresh of your vendor files use:
composer update --prefer-source

Leave a comment

Your email address will not be published. Required fields are marked *