How to use Git when contributing to Open Source projects.
Hello, peeps! I am Plxity (Apoorv Taneja) an active open source contributor in organisations like FOSSASIA, P5.js, Tensorflow etc.
In this article, I am going to give a brief introduction to using Git when contributing to Open Source Projects.
Make sure you have already installed Git before moving forward
So without wasting any more time. Let's begin...
1) Select a project you want to contribute to.
2) Fork the Project.
3) After the second step, go to the forked project in your repositories.
4) Copy the repository link.
5) Open your terminal and execute
git clone <copied link in step 4>
6) Go to the cloned project by using the command
cd <project-name>
7) Execute the next command.
Go to the original repository and copy its link as did before in step 4.
git remote set upstream <mention original repo link>
8) To verify if you have successfully set up the remote link to the original repository, execute the next command
git remote -v
You will see two different links, origin and upstream.
9) Check the current branch
git branch
10) Pull the latest changes from the original repository
git pull upstream master
11) Now we have to create a new branch
git checkout -b <new-branch-name>
12) Now check the current branch
git branch
You will notice we are on the new branch which we created just now.
Make the necessary changes in the project
13)
git add .
To add all the changes made in the project by you.
14)
git commit -m "<meaningful-commit-message>"
Write a meaningful commit message about the change made.
15)
git push origin <branch-name>
and you are done. You have successfully created a new branch, made the changes and have pushed them. Now last and the final step to raise a PR (Pull Request).
16) Go to the original repository page on GitHub.
17) Click on Pull Request tab.
18) You will see something like this.
19) Click on compare & Pull request
20) A new page will open up
Mention the changes made in the PR and click on 'Create Pull Request'
So after this step, you have successfully raised a PR in the project repository. You can check it in the PR tab. Now, wait for the mentors/maintainers of the project to review your PR and merge it.
Hope you guys understood the basics for raising a PR using git. In case of any doubt, please feel free to reach out to me.