What is the Difference between Pull and Merge Requests in Git?

What is the Difference between Pull and Merge Requests in Git?

GitHub, built on top of Git, is a web-based platform that provides developers with a suite of tools for managing their codebases and repositories, including pull and merge requests. Although these terms are often used interchangeably, they have distinct meanings in GitHub.

Let’s find out!

What is a Pull Request?

A pull request is a request from a contributor to merge their changes into a project's main branch in Github.

It is called a pull request because the contributor requests that the project maintainers pull their changes into the main branch. The maintainers will review the changes and make comments. If everything looks good, they approve and merge the changes into the project's repository on GitHub.

Pull request is a term commonly used in Github

Example

To create a pull request after making specific changes in a project, follow these steps:

  1. Add all the new files and folders or the ones you made changes to using the git add . or git add -A.

  2. Commit the changes with a concise and detailed description using the git commit command

git commit -m "description"
  1. Push the commit to the current branch or a desired branch of the project using the git push command
git push origin branch

By doing this, you’ve successfully made a pull request.

The project manager will be notified about the request and they will merge your changes if there's no conflict with the main branch.

What is a Merge Request?

A request which leads to merging one branch into another in Gitlab is referred to as Merge Request

In GitLab, a merge request is a way to propose changes to a project's codebase. It allows team members to review, discuss, and collaborate on proposed changes in the source branch before merging them into the target branch.

The source branch is where the changes were made while the target branch is where a developer request to merge their changes into.

The basic idea is the same in both pull requests and merge requests in Git: both are requests for changes to be merged into a codebase, and both involve a review process before the changes are accepted.

In essence, the major difference is that:

Merge requests are used in Gitlab while pull requests are used in GitHub.

The terms have the same functionality but in different settings.

Below is a step-by-step guide to creating a merge request in Gitlab:

  1. Fork the Repository: If you already have access to the repository. Developers only need to create a fork if they are not a direct contributor to a project.

  2. Clone the Repository: Clone the repository to have it on a local machine using the Git command-line interface or a Git GUI tool. This allows working on the code and making changes.

  3. Create a New Branch: Create a new branch in the local repository to isolate changes. This helps keep the main branch clean and allows for easier management of multiple changes.

  4. Make Changes: Make the necessary modifications, additions, or deletions to the codebase according to the requirements or bug fixes.

  5. Commit Changes and push the new branch: Commit them to the local branch once the changes have been incorporated. It's essential to provide a descriptive commit message that explains the changes made. After that, push the local branch to the remote repository on GitLab. This makes the changes visible to others and allows for collaboration.

  6. Create a Merge Request: On the GitLab project page, navigate to the repository and click on the "Merge Request" button or the "+" icon next to the repository's branches. Select Source and Target Branches: In the merge request creation form, choose the branch with the changes as the "Source Branch" and the desired branch where the changes are to be merged as the "Target Branch." The target branch is typically the main or development branch. Equally important, write a clear and concise description of the changes made, providing context and any additional information. Assign reviewers who will assess your changes for quality and correctness.

    1. Select Source and Target Branches: In the merge request creation form, choose the branch with the changes as the "Source Branch" and the desired branch where the changes are to be merged as the "Target Branch." The target branch is typically the main or development branch. Equally important, write a clear and concise description of the changes made, providing context and any additional information. Assign reviewers who will assess your changes for quality and correctness.

  1. Submit the Merge Request: Once the above is done, submit the merge request. This action notifies the assigned reviewers and project maintainers about your proposed changes.

  2. Review and Address Feedback: Reviewers will examine the changes and may provide feedback or request modifications. Address the feedback and make the necessary adjustments to the code based on the comments received.

  3. Resolve Conflicts (if any): If there are conflicts between the source branch and the target branch, resolve them by merging the target branch into the local branch, resolving conflicts, and pushing the changes again. At this point, mark the merge request as "Ready for Merge" to indicate that it's ready to be merged.

  4. Merge the Request: Once the changes have been reviewed and approved by the project maintainers, they will merge the changes into the target branch, incorporating the modifications into the codebase.