Table of Contents
Pull requests (PR) are a core feature of GitHub that allows developers to review, discuss, and merge changes into a project’s main branch. In this guide, we will explore how to create, manage, review, and merge pull requests into the main branch, ensuring your project follows a clear and organized development process.
What is a pull request?
A pull request is a method for developers to notify project maintainers about the changes they have made in a branch. When submitting a pull request, the changes are not automatically merged into the main branch. Instead, it serves as a request for a code review and a final decision on whether to merge the changes.
Why use pull requests?
Pull requests are useful for collaboration, especially in open-source projects or when working in teams. They ensure code quality through review processes, facilitate discussion, and help prevent unwanted or buggy code from entering the main branch. The ability to merge or reject changes also gives project maintainers more control over the codebase.
How to create a pull request on GitHub

Step 1: Create a new branch
Before making changes, always start by creating a new branch. This ensures your main branch stays clean and you can isolate specific changes for review.
git checkout -b feature-branchIn this example, feature-branch is the new branch where your changes will live.
Step 2: Make changes in the branch
Once you’ve created the new branch, you can start working on the changes or features you want to implement. Add your new files or modify existing ones, and then stage and commit the changes.
git add .
git commit -m "Implemented new feature"Step 3: Push the branch to GitHub
After committing your changes, you need to push the branch to GitHub.
git push origin feature-branchThis uploads your changes to GitHub, making the branch visible in the repository.
Step 4: Create a pull request

Navigate to your repository on GitHub. You will see an option to compare and create a pull request for the branch you just pushed. Click on “Compare & pull request” to begin the process.
At this stage, you will need to fill in details such as the title and description of the pull request. The description should clearly explain what changes were made and why.
Once you’re satisfied, click “Create pull request.” Your pull request is now open for review.
Managing pull requests

Step 1: Assign reviewers
Once a pull request is created, it is essential to assign reviewers. These are team members or project maintainers responsible for reviewing the code changes.
To assign reviewers:
- In the pull request, click the Reviewers section on the right sidebar.
- Choose the appropriate team members.
Reviewers are responsible for ensuring that the changes meet coding standards, follow project guidelines, and do not introduce any issues.
Step 2: Add labels and milestones
Labels help categorize the pull request, such as marking it as a “bug fix” or “feature enhancement.” Milestones are used to group the pull request under a specific version or project timeline.
Step 3: Start the review process
Reviewers can now review the changes, make comments, or request modifications. If changes are required, the developer will need to update their branch and push the changes again, automatically updating the pull request.
Here’s an example of the command to update your branch after making requested changes:
git add .
git commit -m "Addressed review comments"
git push origin feature-branchGitHub will automatically track these updates and reflect them in the pull request.
Reviewing pull requests
Reviewing code
When a reviewer inspects a pull request, they should go through the code and check for potential issues. GitHub allows you to comment directly on lines of code, making it easy to point out specific areas of concern or improvement.
Requesting changes
If you spot issues that need to be resolved before merging, you can request changes. This sends a notification to the author of the pull request, who will then make the necessary updates and push them to the same branch.
Approving a pull request
If everything looks good and you’re satisfied with the changes, you can approve the pull request. Once approved, the pull request is ready to be merged into the main branch.
Merging pull requests
Once a pull request has been reviewed and approved, it’s time to merge it into the main branch. There are several merge options in GitHub:

Squash and merge.1. Merge commit
This is the default option, which merges the changes while preserving the entire history of the branch.
git merge feature-branch2. Squash and merge
This option compresses all commits in the branch into a single commit on the main branch. It’s useful for keeping the main branch clean and concise.
3. Rebase and merge
Rebasing puts the commits from the pull request on top of the main branch, giving a linear history. This method is often used to keep the project history clean and readable.
To rebase the branch, use:
git rebase mainAfter selecting your merge option, click the “Merge pull request” button in GitHub.
Closing the branch

Delete branch button.Once the pull request is merged, you can safely delete the feature branch from both your local and remote repositories.
git branch -d feature-branch
git push origin --delete feature-branchConclusion
Pull requests are an essential part of collaborative development on GitHub, helping ensure code quality and project integrity. By following a structured process of creating, reviewing, and merging pull requests, teams can work together more efficiently and maintain a high standard for their codebase.
Whether you are working on open-source projects or within a private team, mastering pull requests will improve the quality and organization of your development process.