How to Contribute to Open Source?
» My first open source? ๐ค
Hi there,๐๐ป Today we are going to look into my first open-source contribution and also how you can contribute to open source projects. I am not going to lie, it was such a difficult task to do. But once I figured out how to start, it became a lot easier.
When I first thought about contributing, I got confused regarding where do I start?๐ค How do I find the correct repository? And how do I create a Pull Request? ๐๐ปโโ๏ธ
But Then Of course I did some research ๐ and saw various tutorials. But then again trying out something new can be so so so overwhelming. And one day I finally created a pull request. (ps: It wasn’t merged but still.๐คช) Then I did my second contribution but as they say, “time is precious"โฑ๏ธ, even though my second pull request was correct but someone did it before me, and because of that my second contribution wasn’t merged either.๐ญ
When I was making the above video, I already have a third pull request created, and before they can merge it; there were some discussion going on.
And Suprise: (MY PR WAS MERGED)๐ค
» Your first open source contribution ๐ฅ
But now what I want to tell you is the process of how to start your 1st ๐ฅcontribution.
» Step 1: Find a perfect Repository ๐
-
So the first step is to search for a repository that is open so you can contribute to it.
-
And to find the repository to contribute, there’s an amazing repository which I came to know it this: awesome for beginners repo.
-
This is not the only source. (ps: trust me ๐)
-
We have another set of links through which we can find the correct repo for our contribution. ps: (I’ll be using short forms; PR = Pull request, repo = repository and so on, cause duh, its too long. ๐ฎโ๐จ)
-
List of sources:
๐๐ป GitHub Explore
๐๐ป Open Source Friday
๐๐ป First Timers Only
๐๐ป CodeTriage
๐๐ป 24 Pull Requests
๐๐ป Up For Grabs
๐๐ป First Contributions
๐๐ป SourceSort
๐๐ป OpenSauced
» Step 2: License and Contribution Guidelines ๐
-
Now that you have selected a project to contribute to. The next thing that you need to look for is a License. Because A project on GitHub is not an open source unless it has a license.
-
So first do check their License also they will have a contributing guideline about how you can contribute to their project, so read them first properly. It might take you a few minutes(or hours, yes ๐ซ ) but please do read it first. I got legit overwhelmed by just looking at different projects contributing guidelines. But then I decided on one particular project and stuck to it.
» 3. Step 3: Fork the repo
-
After you have successfully found a project, and read its License and Contributing Guidelines next step is to fork that repo. And that’s so easy.
-
Go to the project repo and there you will have a fork button on it.
-
Click on it and it will ask you to name that fork repo, so name it and then click Create a fork and that’s it.
- Forking a repository means creating a copy of it in your GitHub account. Why we are forking it because of course, the project owners don’t authorize contributors to directly push the changes to the main or upstream repository.
» Step 4: Clone the forked Repository:
- Cloning means we create a copy of a repo in your local environment.
- So now that we forked a react repo; search for it in your accounts repository section and there you will have the green code button; click on it and then copy the HTTPS link and then in your terminal type the command:
git clone <repo-name>
- Navigate to the project directory by running the command cd followed by the project name.
git clone <project name>
» Step 5: Search for an issue to work on:
- Go to the project repo and search for the issue in the issue tab.
- Every open-source project would have a tag “first-timers-only” or “good first issue” etc.
- So go into the labels section and search for the “first-timers-only” or “good first issue” tag.
-
Once found, click on it and there you will have the issues which are only for beginners. But don’t stop here, select the issue, do research, and then when you understand start making changes to the project that you cloned into your local machine.
-
IMP: But before that, you should create a new branch; which is also our next step.
» Step 6: Create a New Branch
-
Whenever we are working on an issue the best thing is to create a new branch.
-
This will helps keeps the upstream branch (main branch) clean.
-
To do so; we can run the following command that is
git checkout -b <branch-name>
-
Branch name = what you want your branch to be called.
-
And a branch name shouldn’t be anything, please. The branch name should refer to the changes that you are going to make.
-
Like for example: fix/link-in-about-section or if you are creating a new feature it would be like: feature/add-dark-mode or Something like this.
-
Now that we have set the branch completely start to make changes in your new branch.
» Step 7: Add changes to the staging area and commit
- Once you have made the changes, the next thing is to add the changes to a staging area and then commit them. So to add the changes we have a command
git add .
and then run the command
git status
to check the name of files that have been changed.
and then commit the changes by running the command:
git commit -m "your message"
- Sometimes you might be stuck on some issue so what you can do is still commit the changes by running the command:
git commit -m "WIP: Cannot run the test"
- Or something like this. WIP = Work in progress.
» Step 8: Update your forked repo with the main/upstream branch.
-
Before pushing your changes first look at if your origin branch is up to date with an upstream branch or not. And if not, update it first. Because it might be possible that the upstream repo had already merged some pull requests and made some changes.
-
How would you know if your branch is out of date by going to the repository and then in the sync fork button you will have the following heading (shown in image below): so click on the update branch and once done pull all those changes to update your local repo.
- To pull the changes run the following command in terminal:
git pull origin main
- And that’s it. Now finally we will push the changes to the origin repository.
» Step 9: Push the changes.
- Push the changes to the forked repository or origin repository as it is called.
To push the changes run the command in terminal:
git push origin <branch-name>
- Branch name = one that you gave earlier. (Remember?๐คช)
» Step 10: Create a Pull request:
- Go to the origin repo and there you will find compare and pull request (shown in picture below) after you have committed your changes. So click on compare and pull request.
-
Then you fill out a form to fill up. Different Projects have different templates. So fill that and at the end don’t forget to write a clear description of your changes if you have screenshots of what changes you have made, attach them, and also specify which issue number you have worked on and write Closes #issueNumber.
-
And at last, click the button, to create a pull request.
-
And there, Congratulations ๐ฅณ๐ฅ you have made your first pull request. Be proud of yourself. ๐ฅ It’s a good feeling right!?
-
And Now wait for the repo memvers to ckeck your changes, and if it was perfect, your pull request will be merged and if not, don’t lose hope, it might be possible you did some mistake and that’s perfectly fine. We learn from the mistakes right? ๐ฅน
-
So improve that and go onto to your next pull request.
And thar’s it for this post. I hope it was helpful. Alright then Ill seeeee youuu in the next one, till then do alot of contribution okay? Bye Bye and happy contributing! ๐ฅฐ