Contribute in open source projects is one of the coolest things in development area. I also remember, that some years ago, the topic of one edition of FEMUG was exactly this: the contribution in open source projects.
It’s common to be ashamed to contribute with some project, and one of the reasons for it is because you don’t think you have something to contribute. And that’s the point: you can start with anything: a simple revision of code or even a translation.
As you get used to contribute, the proccess becomes automatic. But for a person who is going to contribute for the first time, some parts could be confusing.
A simple step by step could be something like that:
- Fork of the project to your Github user.
- Clone of the project forked in your machine.
- Your magic contribution.
- Updating of your project version with the original project.
- Send your commits to your GitHub.
- Open a pull request to the original project.
Believe it: doing is easier than writing. The step four was the most confuse for me. And that’s why I decided to show here.
The upstram guy
Let’s suppose that we foked the project 2017-is-awesome to our GitHub user account. So, at this moment, the original project and your fork are at the same point and equal.
So, we start to make a lot of changes in our version of the project and we commit them. Simultaneously, you realize that the original project merged a pull request. Now, the projects aren’t equal: actually they have a lot of diferences.
- Your local project has all your changes.
- The original project has new changes from the pull request merged.
If you send your changes to GitHub and try to open a pull request, you are going to realize that it wouldn’t be possible. For do that, we have update our local project with the original; and that’s when the upstream will help us.
Let’s say you are contributing with my simple blog (the code is really old!). We add a remote based on the original version of the blog:
$ git remote add upstream https://github.com/raphaelfabeni/raphaelfabeni.github.io.git
After that, we have to update the upstream:
$ git fetch upstream
With the upstream updated, we have to
merge/rebase our local version (supposing you’re on the
$ git merge upstream/master master
Now if you want to update your Github repository with your local repository before making your changes and commit them, we do:
$ git push origin master
And that’s it! Now our local project is sync and updated with the original version, and if you send the changes to GitHub, the pull request will be enabled.