Recently, I have started contributing to Ruby on Rails — the popular web framework for quickly building web applications. I have just started but couple of my commits have been merged into rails core & have a pretty good idea on contributing to rails. this guide details how you can start contributing to rails.
Step 0 – Decide what to contribute
It could be a bug or feature that you want aka starch your itch. It could a bug fix in which cause check github issue tracker for existing issues & see if you can fix anyone of them and send a Pull Request. It could be removing a warning from test. Or it would contributing documentation.
Step 1 – Fork & Change
This is rather simple but you must know how to use git – the popular distributed version control system. If you don’t then please following this guide closely & read multiple times until you understand.
- Goto rails page on github & click the “Fork” button on the top. requires github account. so register if not already done. Its free!
- You’ve successfully forked rails, but so far it only exists on GitHub. To be able to work on the project, you will need to clone it to your local machine.
git clone https://github.com/your_github_username_goes_here/rails.git # Clones your fork of the repo into the current directory in terminal
- Create a new branch
$ git checkout -b my_branch
- Create new rails app based on your fork
$ /replace/with/path/to/your/rails/fork/railties/bin/rails new app_name_goes_here --dev
- Do your changes. Now whatever changes you do, would instantly get reflected into your rails app. Once you are okay with said changed, commit them
$ git commit -a -m "Describe your change in this message" # commit your changes. make sure to follow the guidance of a good commit message
Step 2 – Create a Pull Request
so you have made your change, tested it.Sweet! Now, its time to send your awesome changes to rails core team for review.
- Add Upstream:
$ git add remote email@example.com:rails/rails.git
- switch back to master, pull latest changes
$ git checkout master $ git pull --rebase upstream master
- Switch back your branch & Reapply your changes ontop of latest changes of the rails’ upstream master
$ git checkout my_branch $ git rebase master
- In the process of the rebase, it may discover conflicts. In that case it will stop and allow you to fix the conflicts. After fixing conflicts, use git add . to update the index with those contents, and then just run:
$ git rebase --continue
- Push branch to GitHub
$ git push origin my_branch --force
- Open Pull request using github’s web-interface.
Congratulation on your contribution! Now, wait for comments on the Pull request.
Step – 3
Once your Pull request is opened, most probably someone will suggest 1 or 2 changes. hers is how to do them:
- switch to your feature branch
$ git checkout my_branch
- make changes & commit
- squash changes into one commit. rule is one feature == one commit
- force push
To close, let me welcome you the world of open source. where code you write gets used by thousands of developers & affects lives of millions of people around the world. Its pretty amazing!