Merge Operation Using GitHub

How to Merge Using GitHub

How to merge branches through the command line on the local computer was already explained in the previous chapter. In this section, we'll explain how to merge branches on the GitHub web platform.

The merge feature on GitHub gives similar functionality as the Git commands below. There are three merge approaches which are a combination of the three Git commands: the git merge, git rebase, and git commit commands.

  1. Create a merge commit: git merge --no-ff
  2. Squash and merge: git merge --squash + git commit
  3. Rebase and merge: git rebase + git merge

1. Create a merge commit

This approach is the one most commonly used. According to this approach, the base branch captures and keeps all the commit histories from the topic branch as shown in the illustration on the left of the main figure.

2. Squash and merge

When you want to integrate all the small commits to simplify the commit history of the project, you can use this option. A drawback of this option is that all the commits of the topic branch are erased from the history as shown in the middle illustration on the main figure.

3. Rebase and merge

If you have many branches in the project and merge them into the master branch, the commit history of the project becomes very complex. This option is used to make the commit line straight as shown the illustration on the right of the main figure.

For a better understanding, please go through the following practice section.

Practice

Objective:
Learn the merge operations on the GitHub web platform

In this practice, we'll go through the three merge approaches on GitHub using the branches prepared on the previous pages. The target operations are illustrated below.

Git Local repository and GitHub remote repository status illustration: 3 merge strategies
  1. Create a merge commit: merge Branch_C into the master branch
  2. Squash and merge: squash and merge Branch_A
  3. Rebase and merge: rebase and merge Branch_B

1. Create a merge commit: merge Branch_C into the master branch

On the previous page, we have already explained about the pull request process until a reviewer approves the changes (Developer A already approved Developer B's code).

The merge operation can be done by either party: the requester or the approver of the pull request. In this step, we'll explain the case where the reviewer (Developer A) conducts the merge operation.

bloovee-round-icon.pngAction by Developer A

1) To execute the merge operation, go to the pull request page created on the previous page. Select Create a merge commit in the Merge pull request pull-down and click the button again.

Create a merge commit: merge Branch_C into the master branch: Step 1