How to contribute to open source
I think contibuting to the open source community is the most rewarding action you can do as a developer. Several years thinking I couldn't post anything important or useful, one day just crossed the line and made my first pull request.
Don't think so much, if you can give back some of your work, (even small patches) to the open source community, just do it!
This are the steps I follow using git and Github. There are other source version control software and other repository sites out there, so this of course will vary on those.
Create a Github account (if needed of course)
Generate your SSH key and upload it to github
Navigate to the repository you want to contribute
Clone your account recently in your local machine
So you will work on your machine and onto your forked copy of the repository.
Add a new origin called, for example, upstream with the original repository (not the forked one)
git remote add upstream https://github.com/{author_name}/{repo_name}
This is needed to syncing the original repo with your forked copy
Now if you are contributing a small patch or is a low activity repo, you can commit directly in the master branch. If not is the case, just create a new feature branch and work there. This will help the original author of the repository when merging with the master branch.
git checkout -b {your_feature_branch_name}
Work in your locally cloned repo, on master or your feature_branch
Don't forget to add tests and ensure all is working properly!
Once your work is done, before commiting your work to origin, lets check if the original repository master branch has been updated while we were working on local.
git fetch upstream master
Here you can do a rebase (only if you havn't uploaded any commit yet)
git rebase upstream master
Or if you already uploaded something just do a pull:
Update your code if needed, resolve conflicts, pass tests, etc.
or if you are working on a feature branch
git push origin {your_feature_branch_name}
Go to your Github repo and make a pull request against the branch you were working on, normally master. Put a description of your work as detailed as you can to making the life easier to the original repository author.
Make small commits one for each logical group changes in the code.
Give commits small and descriptive messages.
As said before, create a branch if there is a major upgrade over the original repo.
If make sense, use Travis CI
Push code as clean as possible, order and orgnaize your commits in a logical way before uploading.
Rebase only if the code not uploaded, after that, just merge updates with pull.
Continuing your work after some time
Maybe you commited some changes to one project, and after some months you will want to push new changes. Simply update your local repo with the latest changes:
Then resolve conflics if any (if your old work was finally merged you may not have any conflict), work as usual into your local code and then follow the steps above to make another pull request.
Why not resetting or deleting local repo? Sure you can do a fresh start deleting and forking again your repo, or simply doing a git reset --hard upstream master but please don't do that because your cloned repository is public and may be already being used by someone.