GitHub: Be Social, Contribute, Learn
GitHub was the first true social coding site, and Juri Strumpflohner will introduce you to basic etiquette and requirements, including knowledge of Git and PRs.
Join the DZone community and get the full member experience.Join For Free
github revolutionized the open-source world by building — in my honest opinion — the first true social coding site. it has never been that easy to contribute to a project, whether it is to simply discuss some new features, to file a bug or in the best case to submit a bug fix or new feature patch: a pull request (pr). still, i found lots of devs don’t know how to properly create a pr, yet. with this article i hope to lower that entry barrier.
first of all…learn git
git is the most widely used version control system, especially for open source projects. while you could use svn on github as well, most projects don’t. simply because git is much more suitable for the use case of distributed working, where multiple people from around the world clone, fork and submit new changes to your repository.
that said, you have to know the basics of git and get used to how it works. hence, you should know about…
- fetch, pull and push
- head, master
- add and commit
- reverting and undoing changes
- branching and merging
i highly recommend you to take the time and study these, get used to them, play with some local demo repository where you try them out (without breaking anything). trust me, this will save you a lot of trouble and pain.
this article might help you to get started: git explained: for beginners
create a github account
ok, i have something to contribute. how should i proceed?
search whether someone else already proposed it or already submitted a fix. github has a simple, yet excellent issue tracking system.
if it is a bug, create a failing test, try to reproduce it locally. good repos already have a good test harness in place. then submit your fix as a pr (including a test that verifies it’s absence).
if it is a new feature proposal, i personally recommend getting in touch with the author(s). create an issue and propose your enhancement and new feature. in that way, you gain additional insights from the author or core contributors and especially you avoid to go in the wrong direction. submitting new code that doesn’t get merged because the author thought about it differently hurts. believe me.
check the readme.md & referenced guidelines
definitely check the readme.md, which is automatically rendered in a nice readable way at the root of the github repo. many repos include instructions for building the repository and especially guidelines for contributing, building etc!
thus, verify whether there are:
- guidelines requiring automated tests for your new changes (that’s always a good idea, even if they’re not explicitly required)
- commit messages guidelines (for example: angular.js , atom.io ).
- coding rules
ok, ready to get started!
now it’s time to pack out your git jedi tricks.
step 1: fork the repo
the first step is to fork the repo you’d like to contribute to. github does that for you, simply search for the fork-button:
this will automatically create a copy of the repository under your own github user profile.
step 2: clone your forked repo
now that you have a copy within your own github user profile, you have full read/write access and you’re ready to apply your change/feature implementation to the codebase. clone your fork and start coding.
at this point we have to speak about "git flow". this term comprises a couple of strategies and good practices when working with git. here are a couple of helpful articles:
if you don’t wanna dive into it right now, at least create a feature branch for your change. this is highly recommended.
$ git checkout -b my-new-feature
now it’s time to code: implement your changes.
step 3: polish your history, squash unnecessary commits
usually when you develop, you may have lots of commits, even intermediate ones, with commit messages that probably only you understand (if even...).
to polish your history and only include those that are relevant and help the author to more easily review your changes. here’s how to do it:
polish your feature branch commits
step 4: push it to your forked repository
now, push your branch to your repo:
$ git push --set-upstream origin my-new-feature
step 5: submit your pr
once you pushed your branch to your repo, simply open it on github. a prominently highlighted message should appear, inviting you to create a pr.
click the "compare & pull request" button and fill out the details.
wohooo, you did it! your pr is done!
github also has an excellent guide on how to do it.
btw, you can simply push additional commits to your forked repo’s feature branch and they’ll automatically appear on your pr.
link/sync with the original repo
if your contribution was a one-time bugfix, you can also delete the repo once it is merged. instead, if you intend to contribute further changes, you might want to setup a link to the original repository s.t. you can update your own repo’s master from now and then.
this is done by adding another git remote that points to the original github repository
$ git remote add upstream <the repo url>
once you have that, you can sync it by doing
$ git checkout master $ git pull upstream master
or with a
followed by a
(based on your prefs).
here’s the github help page article that might also help .
contributing is vital for keeping the open source ecosystem alive, and you learn a lot while doing so! at the same time, though, respect the author’s guidelines, be polite and, use emojis, they’re there with good reason! (this might be useful)
Published at DZone with permission of Juri Strumpflohner. See the original article here.
Opinions expressed by DZone contributors are their own.