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 5. Work With Branches

Fast-Forward Merge

Fast-Forward Merge

What is Fast-Forward Merge in Git

As explained, when you are merging a child branch that is simply ahead of the parent branch (no changes were made to the parent branch after the point when you created the child branch), the git merge command simply brings changes made in the child branch into the parent branch without creating a new commit. This merging approach is called fast-forward merge.

In the fast-forward merge, the status of the branches will shift to the one shown in the main figure. This command moves the HEAD of the master branch forward to the point of the HEAD of Branch_A. The merge command doesn't impact Branch_A. Simply, the master branch becomes the same as the status of Branch_A.

We'll explain the fast-forward merge in more detail with command line examples below.

Command Line Example

The command line image below is a demonstration of the commit and merge actions, which are the same as the upper illustration in the main figure. M1, M2, M3, A1, and A2 are the commit messages that were already made before. We'll explain the commands and responses in the command line in four steps.

Fast-forward Merge Command Line Example
  1. Confirm the original commit history status by running the git log command on Branch_A. You can see that the commit histories and branch statuses are the same as the ones illustrated in the main figure.
  2. Switch to the master branch and run the git merge Branch_A command. You can see that this merge is Fast-forward.
  3. Confirm how the commit history looks on the master branch by running the git log command. You can see that the HEAD of the master branch has moved forward to the same position as the HEAD of Branch_A.
  4. To confirm the status of Branch_A, switch to Branch_A and run the git log command. You can see the same result as the one in the master branch. This means that Branch_A and the master branch are in the same status now.

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

Practice

bloovee-round-icon.pngDeveloper A (Project Owner Role)

Objective:
Check how the Fast-Forward merge works

1. Prepare a practice file

In this practice, we'll modify the file and make some commits M1, M2, M3, A1, and A2. In the previous practice, we have already created the git_branch_practice.html file under the git_branch_practice directory. As we already deleted Branch_A and Branch_B, you have only the master branch now. The code on the master branch is like the one below.

git_branch_practice.html (master)
<!doctype html>
<html lang="en">
<body>
<!-- Master Branch-->
<h1>M1</h1>
<!-- /Master Branch-->

<!-- Branch_A-->
N/A
<!-- /Branch_A-->

<!-- Branch_B-->
N/A
<!-- /Branch_B-->
</body>

Make new commits on the master branch

To align with the upper illustration in the main figure, let's make commits M2 and M3 first.

Add M2 under the html file and save it. Then, make a commit with "M2" as a commit message.

git_branch_practice.html (master)
<!-- Master Branch-->
<h1>M1</h1>
<h1>M2</h1>
<!-- /Master Branch-->
Command Line - INPUT
git commit -am "M2"
Command Line - RESPONSE
[master f5ff7aa] M2
 1 file changed, 1 insertion(+)

Repeat the same actions for commit M3.

git_branch_practice.html (master)
<!-- Master Branch-->
<h1>M1</h1>
<h1>M2</h1>
<h1>M3</h1>
<!-- /Master Branch-->
Command Line - INPUT
git commit -am "M3"
Command Line - RESPONSE
[master e12beda] M3
 1 file changed, 1 insertion(+)

Create a Branch_A and make new commits

Next, create Branch_A and checkout to this branch.

Command Line - INPUT
git checkout -b Branch_A
Command Line - RESPONSE
Switched to a new branch 'Branch_A'

To make commit A1, edit the file and save it first.

git_branch_practice.html (Branch_A)
<!-- Branch A-->
<h1>A1</h1>
<!-- /Branch A-->

Make commit A1.

Command Line - INPUT
git commit -am "A1"
Command Line - RESPONSE
[Branch_A 62dda63] A1
 1 file changed, 1 insertion(+), 1 deletion(-)

Repeat the same actions for commit A2.

git_branch_practice.html (Branch_A)
<!-- Branch A-->
<h1>A1</h1>
<h1>A2</h1>
<!-- /Branch A-->
Command Line - INPUT
git commit -am "A2"
Command Line - RESPONSE
[Branch_A a4c4eb0] A2
 1 file changed, 1 insertion(+)

Run the git log command to see the commit history.

Command Line - INPUT
git log --oneline

You'll see the following status shown below. Commit hash is a unique number generated by the computer each time. You'll see different ones on your computer, however, the structure of commit histories and branch status will be the same.

Command Line - RESPONSE
a4c4eb0 (HEAD -> Branch_A) A2
62dda63 A1
e12beda (master) M3
f5ff7aa M2
8bf5c03 M1

2. Perform the merge commit

As you need to run the merge command from the master branch, first switch the current branch to the master branch. Then, run the merge command.

Command Line - INPUT
git checkout master
git merge Branch_A

The command line response shows that the Fast-forward merge is executed.

Command Line - RESPONSE
Switched to branch 'master'
Updating e12beda..a4c4eb0
Fast-forward
 git_branch_practice.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

3. Check commit histories and branch status

Check the status on the master branch first.

Command Line - INPUT
git log --oneline

You can see that the HEAD of the master branch moved forward to the same position as the HEAD of Branch_A. Also, you can confirm that no new commit is created by this operation.

Command Line - RESPONSE
a4c4eb0 (HEAD -> master, Branch_A) A2
62dda63 A1
e12beda M3
f5ff7aa M2
8bf5c03 M1

Next, check the status on Branch_A.

Command Line - INPUT
git checkout Branch_A
git log --oneline

You can see exactly the same results as the ones on the master branch. This means that the master branch and Branch_A are in the same status now.

Command Line - RESPONSE
a4c4eb0 (HEAD -> Branch_A, master) A2
62dda63 A1
e12beda M3
f5ff7aa M2
8bf5c03 M1

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Adding URL Patterns to Django Views

Add URL Patterns

Managing Job Life Cycle

Create, Stop and Terminate Jobs

Initiating Git & GitHub Project

Chapter 3. Git & GitHub Project Setup

How to Remote Collaboration in Git

Git Regular Workflow – Remote Collaboration

Establishing a Link with git remote

Link With Remote Repository – Git Remote

Adding URL Patterns to Django Views

Add URL Patterns

Managing Job Life Cycle

Create, Stop and Terminate Jobs

Initiating Git & GitHub Project

Chapter 3. Git & GitHub Project Setup

How to Remote Collaboration in Git

Git Regular Workflow – Remote Collaboration

Establishing a Link with git remote

Link With Remote Repository – Git Remote

Tags:

Branch

Git Key Commands

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