How to Make Your First Pull Request on GitHub
If you are a person interested in contributing to open source but don’t know how to make a pull request, then this article is going to help you.
What is a pull request?
A Pull Request, or a PR, is a way that allows us to contribute to an open source repository on GitHub.
Note: The repository needs to be public or you need to have permission to be able to submit a PR.
But hold on, are you wondering that how will you be able to follow up the steps since you don’t know how to use Git and GitHub?
Don’t worry, I’ll be walking you through a detailed explanation of the steps you need to follow while making your first PR. You can use this repository to submit your first pull request: https://github.com/niloysikdar/your-first-PR
Let’s make our first pull request!
I think you are pretty excited at this moment. So without any further delay, let us begin.
Okay, so firstly you need a GitHub account and git to be installed in your system.
1. Fork the repository
You can’t push the code directly into someone’s repository as you don’t have permission to do so. Firstly you need to make a copy of the entire project into your account.
Open the repository link in your browser, also make sure you are signed in to your GitHub account. Click the “Fork” button on the top right corner of the page.
After forking, you will see the entire copy of the project in your account.
2. Clone the repository
Once you have successfully forked the repository, you will be redirected to your forked repository. Now you need to clone it into your local machine to start working on it. On your forked repository, click on the green button named “Code”. Now copy the link which will be like : https://github.com/<your_username>/your-first-PR
Open your Command Prompt, terminal, or git bash and move to the desired directory (cd <desired_directory>
) where you want to clone the project and then enter the following command: git clone <copied_url>
Now you have successfully set up a copy of the project in which you will make changes. Now, switch to the project directory using cd <project_name>
.
3. Create a branch
But wait, don’t perform any changes now!
You should create your new branch to execute any changes in the project. The branch name should be short and relevant. To create a new branch use git checkout -b <branch_name>
(Here I am creating a branch called “add-name”, so I will enter the command git checkout -b add-name
).
You can see your current branch name here if you are using git bash.
Otherwise, enter git branch
to view your current working branch.
4.Make your changes
Now it’s time to make the required changes in the project files, maybe fixing a bug, or adding some feature, or correcting a typo.
But for now, you will simply open the CONTRIBUTORS.md
file in any editor and add your name and GitHub profile link to the file.
Save the changes and you are good to go to the next step.
5.Stage and commit your changes
After making your changes, enter git status
and will see that the CONTRIBUTORS.md
file has been modified. If you want to see those changes then enter git diff
. Now you need to add the changes and commit them.
Enter git add .
to add all the files which have changed. Then enter git commit -m “Your commit message”
to commit those changes.
6.Push changes to GitHub
Now you need to push these local changes into your remote GitHub repo. As I told you before, you are going to push the changes to your forked repo, not the original one which you have forked.
So simply enter git push origin <branch name>
( in this case, the command will be git push origin add-name
, as you have done changes into the “add-name” branch ).
Well done, you have successfully pushed the changes into your GitHub repo. But wait, you are not yet done.
7.Create Pull Request
You are now on the final step, go to your forked GitHub repository and click “Compare and pull request”.
Add a title and a brief description of your changes, you can also refer to an issue that you have solved using “#”, followed by the issue number.
Click on “Create pull request” and you are finally done.
Hooray, you have created your first pull request.
Conclusion
Let’s recap the steps quickly:
1.Fork the repository
2.Clone the repository
3.Create a branch
4.Make changes
5.Stage and commit the changes
6.Push changes to GitHub.
7.Finally create Pull Request.
Now you have successfully created your first pull request. Explore GitHub, find repositories according to your tech stack, raise issues, and submit PR’s. Keep contributing to the open-source world!
Thank you for reading, if you have enjoyed the article, make sure to show some love by hitting that clap (👏) button!
You can also connect with me on LinkedIn.