Create Your First Pull Request
Make your first Open Source Contribution with opening a PR
Table of contents
What is a Pull Request?
A pull request is a feature provided by GitHub, GitLab, and Bitbucket for collaborative software development. It provides a mechanism for developers to propose changes to a codebase and for other team members to review, discuss, and eventually merge those changes into the main project repository.
Pull requests play a crucial role in fostering a collaborative and controlled approach to managing code changes in open-source projects, as well as in teams working on shared codebases.
How to create a PR?
Fork the Repository:
Go to the GitHub repository you want to contribute to.
Click the "Fork" button in the top-right corner of the repository page. This will create a copy (fork) of the repository under your GitHub account.
Clone the Forked Repository:
After forking, go to your forked repository on GitHub.
Click the "Code" button, and copy the repository URL.
Open git bash, navigate to the directory where you want to store the local copy of the repository and clone it using the command below.
git clone https://github.com/your-username/repository-name.git
Create a New Branch:
Change into the cloned repository's directory.
cd repository-name
It's good practice to create a new branch for each feature or bug fix. This keeps the main branch clean and makes it easier to manage changes.
git checkout -b new-branch-name
Make and Commit Your Changes:
Make the necessary changes to the files in your local repository using a code editor or any other development tool.
# Stage the changes git add . # Commit the changes git commit -m "Descriptive commit message"
Push the Changes to Your Fork:
After committing your changes, push them to the new branch on your forked repository.
Now you will be able to see your changes in the forked repository.
git push origin new-branch-name
Create the Pull Request:
Visit your forked repository on GitHub and switch to the branch you just pushed.
Click on the "Compare & pull request" button next to the branch selection dropdown.
Review the Pull Request:
Give your pull request a descriptive title and provide additional context or information in the comment box.
Review the changes you made to ensure everything looks good.
Submit the Pull Request:
- Once you're satisfied with your changes and comments, click on the "Create pull request" button.
Discussion and Review:
Your pull request is now submitted, and other contributors can review your changes, leave comments, or suggest modifications.
Be prepared to address feedback and make additional changes if necessary.
Merge the Pull Request (if accepted):
If your changes are approved by the repository maintainers and meet the project's guidelines, they will merge your pull request into the main repository.
After the pull request is merged, your changes become a part of the main codebase.
Keep Your Fork in Sync (Optional):
If your pull request takes some time to be merged, the main repository may have new changes in the meantime. To keep your fork up to date refer following commands:
git remote add upstream https://github.com/original-repository/repository-name.git git fetch upstream git checkout main git merge upstream/main git push origin main
This will update your fork's main branch with the latest changes from the original repository.
Congratulations🎉! You've successfully created a pull request on GitHub. Remember that the pull request process may vary slightly based on the project's guidelines, but these steps are the general procedure for contributing to most repositories on GitHub.
That was it for this blog 🙏, I encourage you to explore more into its documentation, tutorials, and resources available online.
I hope you enjoyed it. Do comment with your thoughts about this blog.
If you’re a regular reader, thank you, you’re a big part of the reason I’ve been able to share my learnings with you.
You can connect with me on Twitter and LinkedIn.
Follow me for more such blogs 😊.
Happy Coding✌️!!