Posted on

When working with third-party code you sometimes run into bugs or things you’d like to see improved. In open source software people often work on their code in their own time. And just like yours that time is very precious. In this article I will show you how you can contribute your time to help fixing that nasty bug and help a package maintainer to get your fix into their code.

The examples in this article will be for a PHP project with the code hosted on Github. The fix we are doing will be a simple one, a spelling error in a variable name. First we go to the repository on Github, and to be able to make changes we have to copy the repository to our own account.
This process is called forking and is simply achieved by pressing the ‘fork’-button in the top-right.

Forking a repository
Clone a repository to make it your own

After we have forked the repository it’ll be available in our account and we can clone it to our local machine like one of our own repositories.
Then you can create a new branch, fix the bug and push this to your cloned repository.

Once you’ve got the fix in your cloned repository on the new branch it’s time to send in the change to the original repository. Choose your branch in the Github repository and press the ‘new pull-request’ button as shown below.

Create a pull request to send in your change

Github will now pre-fill the pull request and all you need to do is fill out what change you have made and what it’ll solve. Once you’ve filled out the form you can press the green ‘Create pull-request’ button to send it to the original repository maintainer for review as shown below.

Inform the original author what your change does and why it makes the software better

Once the package maintainer has reviewed your change and merged it in it’ll be available for everyone. If you want to make use of your fix sooner you’ll be able to use your own repository and merge in updates from the remote repository to stay up to date with the latest changes. This is particularly handy if your fix takes longer to merge into the main repository.

So there is no reason to not start to fix those bugs you’re always ranting about. In a follow up article (soon to be placed on this blog) I will, as a bonus, show how you can use your fixed version in Composer before it gets merged when working on a PHP project.