Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Git & GitHub IntroductionChapter 6. Remote Collaboration

Merge Operation Using GitHub

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

2) Press the Confirm merge button to execute.

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

3) A confirmation message is displayed:

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

4) Check the commit history on the master branch. Go to the Code tab and open the commits.

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

You will see that Branch_C was integrated into the master branch while the commits made on Branch_C were kept unchanged.

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

2. Squash and merge: squash and merge Branch_A

In this step, we'll continue to execute the merge operation with the Developer A account. When you want to execute the merge operation by yourself, you can create a pull request on your own and execute the merge operation.

bloovee-round-icon.pngAction by Developer A

1) Create a new pull request from the Pull requests tab and press the New pull requests button.

Squash and merge: squash and merge Branch_A: Step 1

2) Select Branch_A to compare, and press the Create pull request button

Squash and merge: squash and merge Branch_A: Step 2

3) Add a PR comment and press the Create pull request button. As Developer A executes the merge operation himself, you don't need to select a reviewer.

Squash and merge: squash and merge Branch_A: Step 3

4) Select Squash and merge under the Merge pull request pull-down.

Squash and merge: squash and merge Branch_A: Step 4

5) Press the Confirm squash and merge button. The squash merge is executed.

Squash and merge: squash and merge Branch_A: Step 5

6) Check the commit history on the master branch. You can see that Branch_A was squashed and merged. As the original commits are squashed, you cannot see the original commit details (A1LA, A2LA).

Squash and merge: squash and merge Branch_A: Step 6

3. Rebase and merge: rebase and merge Branch_B

Finally, execute rebase and merge Branch_B. We continue the operation using Developer A's account.

bloovee-round-icon.pngAction by Developer A

1) Follow the same process as in the previous step until the merge option selection (creating a pull request comparing the master branch with Branch_B).

For the merge operation, select Rebase and merge in the merge option list.

Rebase and merge: rebase and merge Branch_B: Step 1

2) Press the Confirm rebase and merge button. Rebase and merge are executed.

Rebase and merge: rebase and merge Branch_B: Step 2

3) Check the commit history on the master branch. You can see that Branch_B was rebased and merged – commit B1LA became the HEAD of the master branch.

Rebase and merge: rebase and merge Branch_B: Step 3

4. Update the local branches

All the operations on this page were made on the GitHub platform through the web browser. The changes have not been synchronized in the Local Repositories. In this step, synchronize the changes made on the Remote Repository with Developer A and Developer B's Local Repositories.

bloovee-round-icon.pngAction by Developer A

First, check the latest status of the master branch. You can see that the branch has not been updated yet.

Command Line - INPUT
git checkout master
git log --oneline
Command Line - RESPONSE
4e7dbf9 (HEAD -> master, origin/master) M3LA
4e1a7d9 M2RA
4b30a1c M1LA

Run the pull command and check the log with the --graph option to see the latest commit tree.

Command Line - INPUT
git pull origin master
git log --oneline --graph
Command Line - RESPONSE
* 231b752 (HEAD -> master, origin/master) B1LA
* 6ae3208 Branch a (#2)
*   542b56b Merge pull request #1 from bloovee/Branch_C
|\  
| * 3d69f7a C4LB
| * 6fc9649 C3LB
| * c33e4e8 C2LB
| * 7510fae C1LB
|/  
* 4e7dbf9 M3LA
* 4e1a7d9 M2RA
* 4b30a1c M1LA

Repeat the same process for Developer B.

skyblue-round-icon.pngAction by Developer B

First, check the latest status of the master branch. You can see that the branch has not been updated yet.

Command Line - INPUT
git checkout master
git log --oneline
Command Line - RESPONSE
4e7dbf9 (HEAD -> master, origin/master, origin/HEAD) M3LA
4e1a7d9 M2RA
4b30a1c M1LA

Run the pull command and check the log with the --graph option to see the latest commit tree.

Command Line - INPUT
git pull origin master
git log --oneline --graph
Command Line - RESPONSE
* 231b752 (HEAD -> master, origin/master, origin/HEAD) B1LA
* 6ae3208 Branch a (#2)
*   542b56b Merge pull request #1 from bloovee/Branch_C
|\  
| * 3d69f7a (origin/Branch_C, Branch_C) C4LB
| * 6fc9649 C3LB
| * c33e4e8 C2LB
| * 7510fae C1LB
|/  
* 4e7dbf9 M3LA
* 4e1a7d9 M2RA
* 4b30a1c M1LA

The demo code is available in this repository (Demo Code).


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Managing Commands in Linux

Chapter 6. Linux Commands for Command Management

Understanding the Differences Between Pull and Fetch

Pull vs. Fetch

How to Run a Django Development Server

Run Server

How to Use cd Command in Linux

cd (Change Directory)

Understanding Relationship Fields in Django Models

Django Models – Relationship Fields

Managing Commands in Linux

Chapter 6. Linux Commands for Command Management

Understanding the Differences Between Pull and Fetch

Pull vs. Fetch

How to Run a Django Development Server

Run Server

How to Use cd Command in Linux

cd (Change Directory)

Understanding Relationship Fields in Django Models

Django Models – Relationship Fields

Tags:

Remote Repository

Remote Collaboration

Merge

Git & GitHub Introduction
Course Content

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features