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.
Install Git from this link:- https://git-scm.com/downloads
To check the Git version
To set the global Git username & email address
git config --global user.name "your name" git config --global user.email "your email"
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.
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
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
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
3. Shift to your branch from master (
By default you're on main branch. So to switch from main, use the following command.
git checkout YourBranchName
Make changes in the project.
4. Add all the changes you've made.
git add .
5. Make a commit message of the changes you've made. Learn more about conventional commits here.
git commit -m 'Add my contribution'
6. Shift to the master (
Now, switch back to main branch to merge all the changes.
git checkout main
7. Merge everything from your branch to the master (
git merge YourBranchName
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
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
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
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!