Contributing To Open-Source 101
Table of contents
- 1. Fork the original repo
- 2. Clone the fork repo
- 3. Create work/feature branch
- 4. Make the changes...
- 5. Update our remote and local repo
- 6. Push our changes to the original repo
- 7. Create pull request
- 8. Now, what next?
Hello Fellow CodeNewbies 👋,
It's the last week of Hacktoberfest!
In fact, it's 2 days left by the time I'm writing this 😄.
If you are thinking to contribute, you still have time!
Last year, I wrote an article about how I contributed to open-source for the first time.
At that time, I needed to configure the remote repo that points to the
upstream. I also had to fetch and merge the
upstream from the command line to update the
But now, some things are becoming more simple with some features from GitHub.
In this article, I will walk you to contribute to an open-source.
But before we start, I suggest you read my articles about the ethics in contributing to open-source.
It would help you understand that there are ethics we need to keep when contributing to open-source.
Without further ado, let's do this! 💪
🛠 Note on tools: I'm using GitHub site on browser and integrated bash terminal on VSCode.
1. Fork the original repo
First of all, we want to fork the original repo, and not clone it right away.
Why do we want to fork the repo? You can find the answer in this article.
How to do this?
- Go to the open-source's repo
- Fork the repo by clicking on the "Fork" button on the right top of GitHub.
This forked repo is the
origin repo, while the original repo is the
2. Clone the fork repo
- Go to our repo list and open the forked repo.
- Click the green "Code" button.
Choose from where we want to clone it and copy the link.
Open terminal/command line.
- Direct it to the directory where we want to store the local repo with the
git clone <copied-link>.
3. Create work/feature branch
Now we have the local repo, we are ready to work on our changes.
But before doing so, we need to create a new branch to work on it. Don't make any changes in the
We can name our branch anything we want. For this example, I will call it
git checkout -b working-branch-name.
This command creates a new branch with the name of
working-branch-nameand will direct us automatically to the branch.
4. Make the changes...
We haven't finished making changes, but we want to call it a day
There are times when we haven't finished making our changes and we want to continue working on it later on.
In other words, we are not ready to commit our changes.
Don't leave our work unsaved.
If we don't save or commit our changes, these changes can get carried onto other branches.
So what should we do?
This will save our changes and put the file in its original state before we make any changes.
git stash pop.
This command will give back our saved work and now we can continue to work on our changes.
However, we are encouraged to commit our changes as soon as we make some changes. It will benefit us to have a history of our changes to look back to.
We've finished making changes
git add .
This will add all changes that we made.
git add -p.
We can pick which changes we want to stage, one by one. This command will display hunks of the file diff and ask us to stage them one by one.
You can read more about it here.
git commit -m "Our message of changes here".
5. Update our remote and local repo
We need to make sure that our
original and local repo has the same update with the
upstream before the push.
Go to our forked repo on GitHub.
We will see a
Fetch upstreambutton on the right side.
GitHub makes it easy for us to fetch the updates from the
Click this button and we will get a dropdown menu.
Fetch and mergebutton is in inactive mode, it means that there is no update on the
upstream. If it's green, click it.
originrepo is now having the same updates as the
Go to our terminal.
- Go to our local
mainbranch with the
git checkout maincommand.
This command will fetch and merge the changes from the
mainbranch at the
originrepo to the local
This step is to make sure that our local
mainbranch is up to date with the
mainbranch in the
mainbranch is now having the same updates as the
- Go to our branch with
git checkout <branch-name>.
git merge main.
- Go to our local
You can read question no. 5 in this article if you happen to get a conflict after merging a branch.
6. Push our changes to the
git push -u origin working-branch-name.
This command is telling to push
7. Create pull request
- Go to the
Click the "Compare & pull request button"
It will redirect us to the "Open a pull request" form.
Fill the form with our changes as the title. Write the description of the changes in the body of the form. Include here a reference to the issue as well.
If we need some reviews from the maintainers before merging, we can make a draft of a pull request.
To do this, click the arrow beside the "Create pull request" button. It will give us the dropdown menu. Select the "Create draft pull request" and click the button. Otherwise, click the default "Create pull request" button.
8. Now, what next?
There is no next. That's it!
You've contributed to an open-source! 🎉
Now you can wait for the maintainers to review your pull request 😄.
Thank you for reading!
Last but not least, you can find me on Twitter. Let's connect! 😊