How to Merge the Development Branch Into Master in Git

John Wachira Feb 15, 2024
How to Merge the Development Branch Into Master in Git

This article outlines merging a development branch into the master branch. Often we will find ourselves creating a branch off the master branch for development.

Once we are satisfied with the changes, we can merge them into the master. The question is, which is the safest way to merge the two?

Git Merge the Development Branch Into Master

For easier context, we will employ the example below.

The example below shows a repository with a master branch. We will create a development branch of the master and make some changes.

We will see the safest and cleanest way to merge the development branch with the master branch.

Some may disagree, but the safest and cleanest way of merging development into master involves merging master to development first.

This way, you can deal with merge conflicts while still in the development branch. It will leave your master branch untouched until you are certain of your action.

To merge our master to development, we will first switch to the development branch and run the command below.

$ git merge master

Output:

git merge master

In our case, we have some merge conflicts. While solving conflicts, you might come across parts that need more work.

Since the master is untouched, you can make more edits and try to merge the master to development again until you are satisfied. Now we can merge the development to master.

Switch to the master branch and run the command below.

$ git merge --no-ff development

The merge above will most likely be a fast forward. The drawback of this is Git does not create a commit node meaning that we cannot keep track of when and who merged.

We remedy this by including the --no-ff flag, which creates a commit node.

In a nutshell, you can directly merge a development branch with a master. However, you can opt for the cleaner and safer route that involves merging master to development first, fixing merge conflicts if present, and merging the development to master as the final step.

Include the --no-ff flag in the last step to create a commit node.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Merge