DEV Community

Cover image for How to contribute to open-source for the first time?
Akhilesh Thite
Akhilesh Thite

Posted on • Edited on

How to contribute to open-source for the first time?

Introduction

Getting started with open source and want to make your first PR?
In this tutorial, we'll cover everything from git installation to git commands. Before we start, here's a quick intro to Git and GitHub.

GitHub is widely used code hosting platform in the world, where you can manage, collaborate and develop your software.

Git is version control system, that keeps track of every single commit or change you are making in a project.

Author

Akhilesh Thite

Git installation

Install Git from this link:- https://git-scm.com/downloads

To check the Git version

git --version
Enter fullscreen mode Exit fullscreen mode

To set the global Git username & email address

git config --global user.name "your name"
git config --global user.email "your email"
Enter fullscreen mode Exit fullscreen mode

Now that you've installed git on your local machine, you can start contributing! You can find a repository with "first-timers" issue tag, or here's a repository specifically made for first timers.

STEPS to contribute

Before you follow all these STEPS, make sure you fork the repository in your GitHub account.

1- Clone the repository using HTTPS or SSH (If you don't have 2FA enabled).
This will basically download the git initialized repository on your computer.

git clone https://github.com/<username>/<RepositoryName>.git
Enter fullscreen mode Exit fullscreen mode

Personal Access Token (PAT) is required if you enable 2FA on your Github account [link]. For that, use the following command instead of the normal URL command.

git clone https://<GitHubToken>@github.com/<username>/<RepositoryName>.git
Enter fullscreen mode Exit fullscreen mode

2. Create a new branch.
Creating a new branch allows you to isolate your changes from the master (main) branch. If your changes goes well, you always have the option to merge your changes into the master branch. If things don't go so well you can always discard the branch or keep it within your local repository.

git branch YourBranchName
Enter fullscreen mode Exit fullscreen mode

3. Shift to your branch from master (main) branch.
By default you're on main branch. So to switch from main, use the following command.

git checkout YourBranchName
Enter fullscreen mode Exit fullscreen mode

Make changes in the project.

4. Add all the changes you've made.

git add .
Enter fullscreen mode Exit fullscreen mode

5. Make a commit message of the changes you've made. Learn more about conventional commits here.

git commit -m 'Add my contribution'
Enter fullscreen mode Exit fullscreen mode

6. Shift to the master (main) branch.
Now, switch back to main branch to merge all the changes.

git checkout main
Enter fullscreen mode Exit fullscreen mode

7. Merge everything from your branch to the master (main) branch.

git merge YourBranchName
Enter fullscreen mode Exit fullscreen mode

8. Get ready to push from your local machine.
You cannot directly push the changes from your local machine, to do that we have to create a new connection record to a remote repository. After adding a remote, you'll be able to use as a convenient shortcut for in other Git commands.

If you don't have 2FA enabled, then use the normal HTTPS or SSH link.

git remote add <message> https://github.com/<username>/<RepositoryName>.git
Enter fullscreen mode Exit fullscreen mode

Personal Access Token (PAT) is required if you enable 2FA on your Github account [link].
For that, use the following command instead of the normal URL command.

git remote add <message> https://<GitHubToken>@github.com/<username>/<RepositoryName>.git
Enter fullscreen mode Exit fullscreen mode

9. Push everything on your forked repository.
This will push all the changes you've made to the master (main) branch of your forked repository.

git push -u <message> main
Enter fullscreen mode Exit fullscreen mode

Now, click on Pull Request button, you'll have the option to create a pull request. i.e., <your forked repo> -> <original repo>, That's it you're done!

Thank you!

Top comments (0)