DEV Community

Victor Ogbonna
Victor Ogbonna

Posted on

How to successfully carry out a git pull request:

As a beginner diving deeper and deeper into the world of version control (Git to be precise), a pull request is a very essential piece of knowledge you will need to acquire to be able to surf safely in the world of version control.
A pull request is simply a request to have your code pulled into another branch, it serves as a way to propose and discuss changes made in a separate branch of the Git repository before adding it to the main branch. In simple terms, let’s say you’re working on a group project where everyone is making changes to a document, a git pull request is like a way to ask your teammates to review your changes before they become part of the final document. This process aids collaborations and code review among members of a team, ensuring that the code changes are on par with quality and project standards before they are incorporated into the codebase.
In this guide, I’ll take you through the relevant steps for a successful git pull request. They are as follows;
1.Fork the repository:
Go to the repository’s webpage, and click on the “Fork” button, This will create a copy of the repository in your own GitHub account. Please note, that you can only fork a public repository.
2.Clone Your Fork:
Next, you’ll clone your forked repository to your local machine using this command “git clone (repository URL)”.
3.Create a New Branch:
After cloning your forked repository, you’ll create a new branch specifically for your changes using this command “git checkout -b feature-branch”. It’s advisable to give the new branch a descriptive name, that entails the feature or the bug you are working on.
4.Make the Changes:
Make all the changes you want to make to the code on this branch.
5.Commit Your Changes:
First stage your changes with the command “git add” Then, You commit the changes you have made using this command “git commit -m (description of your changes)”.
6.Push to Your Fork:
After committing your changes, you have to push it to your forked repository on GitHub using this command “git push origin feature-branch”.
7.Open Pull Request:
Go to fork’s repository page on GitHub, there you’ll see a “compare & pull request” button, click on it and then follow the prompts to create a pull request. Make sure to choose the appropriate branches for comparison.

8.Address the Feedback:
Make changes to your branch according to the feedback you received. You can continue to push commits to the same branch, and the pull request will update automatically.
9.Merge Pull Request:
Once the maintainers of the main codebase are satisfied with the changes, they will merge the pull request into the main repository. But if you have the permissions, you can also merge the request yourself.
10.Sync Your Fork:
After the pull request is merged, it is important to check if your forked repository is behind the main repository, if it is you can sync it using these steps: first, add the main repository as an “upstream” remote using this command "git remote add upstream (main-repo-URL)". Then, obtain and merge the changes using this command “git fetch upstream” followed by “git merge upstream/main” (or upstream/master).
Also, keep in that these steps may slightly vary based on the Git platform you’re using (GitHub, GitLab, BitBucket).

Top comments (0)