Source Control (4-9-2), Git - Merge in Client Side

This is a series of articles related to Source Control or Version Control issues, from a stand-alone app, such as MS SourceSafe, to a Server app, such as MS TFS (Team Foundation Server), to web services, such as GitHub, AWS, and MS Azure DevOps. We have tried to categorize this series of articles as Source Control or Version Control, but this site does not have these categories. So, we put the articles in the DevOps category, as explained in the Wiki:

DevOps is a set of practices that combines software development (Dev) and IT operations (Ops). It aims to shorten the systems development life cycle and provide continuous delivery with high software quality.[1] DevOps complements Agile software development; several DevOps aspects came from the Agile methodology.

The structure of this article series will cover:

  • Stand Alone App
    • MS Source Safe
  • Server App
    • MS TFS (Team Foundation Server)
  • Online (Cloud) Centralized Service
    • MS Azure: DevOps
      • Boards
      • Repos
      • Pipelines
      • Test Plans
      • Artifacts
    • GitHub
    • AWS GitHub Enterprise
  • Distributed App
    • Git

Because these are huge topics, I will not go through them step by step. Instead, each section will be relatively independent and become a reading unit.

Introduction

We have discussed Merge for TFS in the article, Source Control (2-2), TFS --- Merge. We also discuss a bit about Git Merge in the article, Source Control (4.9), Git --- Merge: Fetch, Pull, Push, and Sync. Now, I will discuss more about Git Merge, 

  • On the Server Side 
    • MS DevOps
    • MS GitHub
    • GitLab
  • In Client Side
    • in Visual Studio
    • by Git Prompt Command

I should emphasize here TFS Merge and Git Merge are quite different concepts. While TFS is server-side centralized software, a client-side interface, such as Visual Studio, is just a dummy interface that is synchronous with the server as an input/output interface. Git is a client-side or distributed Software on the client side that is independent software; it can be an independent system working in the client machine, the conversation to the Server, just push/pull the result to/from the Server to make client and Server synchronously.

In IDE, such as Visual Studio, you must choose either TFS or Git.

Menu Bar => Tools => Options => Source Control => Plug-in Selections, got:

Git:

TFS:

Compared to TFS Merge, Git Merge has more choices, such as from Merge Strategies in Git - GeeksforGeeks, that

  • Fast Forward
  • Recursive
  • Ours
  • Octopus
  • Resolve
  • Subtree

But we will not discuss that kind of complex types; we will only discuss the basic types, say, most often happening in different Source Control Servers, 

  • Merge in Servers
    • Merge in DevOps
      • Merge (no fast forward)
      • Squash Merge
      • Rebase Merge
      • Semi-Linear Merge
    • Merge in GitHub
      • Merge (no fast forward)
      • Squash Merge
      • Rebase Merge
    • Merge in GitLab
      • Merge (no fast forward)
      • Squash Merge
  • Merge in Client
    • Merge in Visual Studio
      • Merge (no fast forward)
      • Squash Merge
      • Rebase Merge
    • Merge in Git --- all types of merges, but we only discuss
      • Merge (no fast forward)
        • Merge Fast Forward
      • Squash Merge
      • Rebase Merge
      • Semi-Linear Merge

We will discuss the contents of this article

  • A - Introduction
  • B - Merge in Visual Studio
    • Merge (no fast forward)
    • Rebase and Merge
    • Squash Commits
  • C - Merge by Git Command
    • Merge (no fast forward): merge from the feature branch to the master branch.
    • Merge (Fast forward): merge from the feature branch to the master branch
    • Rebase Merge: Rebase feature branch onto the master branch
    • Squash Merge: Squash two or more commits into one

B - Merge in Visual Studio

In Visual Studio Integrated Development Environment, we may have the following 3 ways to merge.

  • Merge (no fast forward): merge from the feature branch to the master branch
  • Rebase Merge: Rebase feature branch onto the master branch
  • Squash Merge: Squash two or more commits into one

Test Program:

For better understanding, I make this testing program in Visual Studio.

Master Branch

Feature Branch

They all are starting from commit 577fd5aa at 0/10/2023 12:18:31, as

Merge (no fast forward)

Master checkout

Right Click the feature branch, test1, you want to merge it to the master branch => Merge 'Feature/test1' into 'master1':

The merged result is exactly as what we have in Source Control (4-10), Git --- Merge, the option Merge (no fast forward):

Rebase and Merge

Feature Branch check out: --- due to we want to make a merge into the feature Branch and rebase it:

Right Click the master branch you want to use to rebase => => Rebase 'Feature/test3' onto 'master3'

The merged result is exactly as what we have in Source Control (4-10), Git --- Merge, the option Rebase, and Fast Forward Merge.

Squash Commits

Highlight the commits you want to merge.

  • save A
  • save B
  • save C

Right Click => Squash Commits.

The three Commits merge.

Click Squash, save A, save B, and save C. Three branches are merged into one: save C. Click on new merged save C, see the right bottom. This Branch includes all three changes: A, B, and C.

The changes were used to be in save A. See t\right bottom.

In save B, see t\right bottom.

And in save C, respectively  

C - Merge by Git Command

By Git, we can do all kinds of merges, but we only discuss the major ones.

  • Merge (no fast forward): merge from the feature branch to the master branch
  • Merge (Fast forward): merge from the feature branch to the master branch
  • Rebase Merge: Rebase feature branch onto the master branch
  • Squash Merge: Squash two or more commits into one

Test Program

We use the same test program as used above.

Merge (no fast forward implicitly)

Check the status from the command line: master1 is checked out.

git reflog

Check out master2.

git checkout msater2

Check the status from Visual Studio: master2 is checked out.

Merge test2 into master2.

git merge feature/test2

See the merged result from Visual Studio.

Merge (no fast forward explicitly).

We have

Check out master1.

git checkout master1

Merge feature/test1 into master1 with No Fast Forward.

git merge --no-ff feature/test1

Result in Visual Studio.

Fast Forward Merge: not always work.

Merge feature/test6 into master6 with Fast Forward.

git checkout master6
git merge --ff-only feature/test6

It does not work at all. Now, we know the current commit history like this.

Master

feature

The Fast Forward merge is only working for the structure like this.

Get rid of the added commits, save 1 to save 5.

As expected, the Fast Forward merge is working.

Result in master6 in Visual Studio.

Squash and Merge

Master

Check out master4.

git checkout master4

Sqush Merge

git merge --squash feature/test4

The result is not committed, as seen from Visual Studio.

A message editor is open before you can commit the change.

Change to save or quit the editor. The commit makes the merge done.

See it from Visual Studio:

Rebase Merge:

Feature

Master

Rebase feature/test3 onto master3.

git checkout feature/test3
git rebase master3

Seen results from Visual Studio.

Semi-Linear Merge

It is a mix of Rebase and Merge. The above description is for a process where we push a commit to the Server, say to DevOps, and then the pushed feature branch will be rebased onto master and then merged into master. Let us demo this process from the client side:

  • As demoed above in Rebase Merge, we have rebased feature/test3 onto master3

master3

rebased test3

Merge test3 into master3

git checkout master3
git merge feature/test3

 

Result in Visual Studio.

Reference


Similar Articles