Pull requests are the way of contributing or collaborating on a project on GitHub. Let’s say you want to contribute to a repository on GitHub, maybe fix a bug or a typo. Since you don’t own the repository, you can’t directly make the changes. So, what you do is, you simply make a copy/fork of the repository, make changes, and create a pull request.
When you create a pull request, the owner of the original repository is notified that you have created a pull request and proposed some changes. The repository owner can review the changes, merge them, ask for a revision, or even discard them. This is how pull requests work on GitHub.
🔥 FUN FACT
Ever wondered why it is called pull request, not push request? The reason is that you ask the repository owner to pull changes from your copy.
⚡ Steps to Create A Pull Request
According to our understanding of how pull request works, there are three basic steps to create a pull request:
- 🎗 Fork the repository
- 🎬 Make changes in copy
- 🎯 Create a pull request
→ Fork the Repository
To fork a repository, open the repository and click on the Fork button at the top left corner. For example, I am forking this Hacktoberfest repository by Ahmad Awais.
→ Make Changes in the Copy
Next step is to make the changes in the copy i.e fix the typo, bug, or whatever you want to contribute. You can either do it directly on GitHub – I will be doing in this guide – or you can clone the repo and push changes from your machine.
At the time of writing this piece, I just noticed that there’s a colon missing in front of a heading in this repo. So, I am going to propose a fix for it.
Since it’s a minor fix, I can simply go ahead and edit the file on GitHub. However, I do not suggest to edit files on GitHub for major changes in the repo. To do so, open the file in your copy of the repo and click on the Edit button at top right corner.
Clicking on the icon will open the file for editing. Make the changes you want to do and scroll down the screen. At the bottom, you’ll see a section named Commit changes. In this section, you provide the description and title of the proposed changes. Fill in the details and click on Commit Changes button.
Once you have clicked the Commit changes button, your changes will be saved in the file. Now, your copy of the repo is different from the original repository and you can create a pull request.
⚡ Tips on Writing a Good Git Message by Ahmad Awais
- Every Pull Request must have a title.
- Every Pull Request must have a description.
- Write the title and description of what you have done in the imperative mode, that is as if you were ordering someone.
- ✅ DO: Start the line with “FIX“, “NEW“, “IMPROVE“.
- ❌ DON’T: Start with “Fixed“, “Added“, “Adding“, “Improved“.
- 🎯 Read → How to Write a Git Commit Message
- Don’t end the summary line with a period – it’s a title and titles don’t end with a period.
- Have fun. 🎉
→ Create Pull Request
Once you have made changes to the copy of a repository, the next step is to create a pull request. To do so, open the copy of a repository and click on the Pull Request option.
It will show you a detailed comparison between the original repository and your copy. Modified files are displayed side by side where you can review your changes before you finally create pull request. Remember:
✅ Green lines show the modified or newly added part of the file.
⛔ Red lines show the removed part of the file.
After reviewing the changes, click on the Create Pull Request button at the top. It will open a new window asking you details about the pull request. By default, it picks up the commit message details.
Again, use the tips shared above to write a proper pull request message. Finally, click on Open pull request button to create a pull request.
🔱 Sometimes the repository owner adds a code of conduct and contributing guidelines to create a pull request. In case, if there is any guideline by repository maintainer, make sure you follow that. It helps them quickly understand the pull request and review it.
For example, in the above pull request description, I answered a question in the description i.e What does a pull request do? – IMPROVE. It was a part of contributing guideline to easily understand the proposed change. That was all for it! If you have any questions feel free to ask in the comments below.
Peace. ✌
🙌
SUBSCRIBE TO DEVELOPERS TAKEAWAY!
A Premium Development Newsletter by TheDevCouple! What is TheDevTakeaway?