Contributing to open-source projects is a way to give back to the software community and help improve the quality of the software that you and others use Also, note that contributing to open-source projects is not at all about coding as some find it intimidating and confusing you can contribute in other ways For example:
Fixing Typos
Improving documentation
Fixing Bugs
Open source refers to source code that is made available to the public to view, use, modify, and distribute under a license. It’s usually developed and maintained collaboratively by a community of its users. Some well-known open-source projects include Django, Postgres, MongoDB, Vue, Go, Ruby, TypeScript, Git and so many more.
Are you ready to Contribute? Let go
1. Find a Project
Finding a project to contribute to is a difficult task. It is better to contribute to the smaller project first than to dive into bigger projects to contribute.
So let's learn to contribute using the first project/repository I have contributed to which is an Open Source resource for learning Data Structures & Algorithms and their implementation in any Programming Language.
Link to that repository https://github.com/TheAlgorithms
2. Basic Git Commands
You should know basic git command like how to add files, commit and push.
The basic workflow to contribute is as follows:
Fork the repository to your Github account.
Clone the project on your machine.
Create a branch before making any changes to the code.
Commit after making changes to the code and push the changes.
Open a pull request
The above workflow is the basic way to contribute to any project.
3. Fork the repository
Let's fork the project which we will be contributing to from
https://github.com/TheAlgorithms/TypeScript
Why do we fork and not clone the repository?
When we fork the repository we make a copy of it in our account, therefore we can work on it without affecting the original repository.
On the other hand, cloning downloads the project on our machine. Also, we cannot make changes to the repository if we only clone it. As we do not have authorization to that repository.
By forking the project, we can make changes and submit pull requests.
4. Clone the Project
Now clone the project from your account. Go to the repository to find the link
To find the repository URL, click on the green button saying code
and copy the URL as shown below in image 2.
After copying the url, go to the terminal and run the following command (replace URL with yours):
git clone
https://github.com/MohdFaisalBidda/TypeScript.git
After downloading, open it in VS code Editor.
5. Create a Branch
Before making any changes to the code, it's important to create a branch. It helps people to work on the features of the project without getting any conflicts. As each branch is independent of other branches changes in any other branch are not visible unless they are been merged.
In simple words, any changes to be made in code are done using branches.
But before creating a branch we need to add a remote upstream URL from the forked repository to our local repository to pull and push the code using the command below:
git remote add upstream <url>
You can create a new branch and switch to it as follows:
git branch <Your-branch-name>
git checkout <Your-branch-name>
Alternatively, you can do this by using a single command to create and switch to the branch as follows:
git checkout -b <Your-branch-name>
As we have created a branch we are ready to make changes to the code!
6. Make Changes
In this step, we have to make changes in the repository. I advise you to first check the issues in the repository and then make the necessary changes.
Like in this case, we can add any maths function in the typescript language which is listed in issues of the repository.
so we will add a simple function to convert the degree to radians in typescript, with its test written in jest i.e a javascript testing framework.
7. Publish Your Changes
The first step is to add all your changes to the staging area. The add
the command includes that file in the commit which is to be sent to GitHub.
Run the following commands to add files:
git add . //add all files
git add <file-name> //add a specific file
git add .
adds all files to the staging area For example if you make changes to 5 files it will add all 5 files to the staging area. On the other hand, git add <file-name>
adds a specific file to the staging area and the other files stay in the unstaged area.
Commit Your Changes
We have added the changes to the staging area now we have to commit them.
Committing files means saving the updates to the local Repository. It is the same as saving a file after making some changes to it.
git commit -m "Added math function"
In the above command git commit
-m flag stands for "message" which is used to summarise the changes. It is used to describe what has been done/added concisely and descriptively.
Push Your Changes
The last step in publishing the changes is to push the code to the remote repository. Until you "push" changes, the code is only available to the local repository and only visible to you.
To push the changes, run the following command:
git push -u origin <your-branch-name>
We are almost done! The last step is to create a Pull Request.
8. Open a Pull Request
If you have done all steps right now then you should navigate to the repository URL from where we have forked the project.
You can go to the pull request tab > Click on compare & pull request in green
After clicking you will be navigated to a new page to create a pull request as shown below:
Before submitting the pull request make sure you read the contribution guidelines for how to specify the pull request in the title and description.
Now click on the green button saying create a pull request
and you are done! Now just wait for the maintainers to review your code.
WHY DO YOU NEED A PR?
By opening a pull request, other people can see the changes you’ve made to the codebase. Additionally, it allows other members to do a code review.
By creating pull requests, you protect the codebase from unwanted additions. Without pull requests, everyone can merge whatever they want to the main branch. Thus, the code quality will suffer.
Conclusion
🎉 Well done for learning the most basic Git workflow you can use to make open-source contributions. Also, well done for making your first open-source contribution if you followed the article!