Cyberithub

How to Merge Git Release Branch with both Master and Develop

If you are following a branching strategy in which you first start working on a release by creating a release branch from develop and then deploying your release branch in pre production environment post approval. Once all the testing is completed and it is ready to be promoted in production then you need to first merge your release branch with master and then later with develop. So the next time, when you are working on a hotfix or on a release or feature then you can start working by just creating a branch from develop.

While the above steps looks quite simple but sometimes implementing this can be quite challenging in a real environment where you might encounter few issues. So it is utmost important to run all the steps accurately to avoid any unforeseen error.

Lab Setup

In my Lab setup, I have three branches in Bitbucket - release-1.0.1, develop and master. Usually develop and master branch contains the same files. In other words, develop is the exact replica of master. But since master is critical for production so all the release branches starts from develop. Here release-1.0.1 branch is created from develop. Along with that it also contains all the changes that we need to add in the next release. So once my release branch is ready to merge because the deployment can only happen from master as per our branching strategy so we need to first merge release-1.0.1 branch with master and then with develop. So that both master and develop contain the same files.

How to Merge Git Release Branch with both Master and Develop

How to Merge Git Release Branch with both Master and Develop

Also Read: Solved: "error: src refspec master does not match any" when using git push

Step 1: Prerequisites

a) You should have a running System(in my case it is Ubuntu 20.04 LTS) with git package installed.

b) You should have access to clone the Repo.

c) You should have commit access to master and develop branch.

 

Step 2: Clone the Repo

Here we will first clone the example-app repo from Bitbucket project using below git clone command. This will create a local directory called example-app containing all the cloned repo files.

cyberithub@ubuntu:~$ git clone https://app.cyberithub.com/bitbucket/scm/application/example-app.git
Cloning into 'example-app' ...
remote: Enumerating objects: 499, done.
remote: Counting objects: 100% (499/499), done.
remote: Compressing objects: 100% (332/332), done.
remote: Total 981 (delta 324), reused 454 (delta 332), pack-reused 876
Receiving objects: 100% (981/981), 1.01 MiB | 156.000 KiB/s, done.
Resolving deltas: 100% (820/820), done.
Updating files: 100% (267/267), done.

 

Step 3: Create Local Master branch

As our branching strategy allows to make a copy of develop branch only so by default our current residing branch will be develop. If you go to the cloned directory and check the current branch then it should show like below.

cyberithub@ubuntu:~$ cd example-app
cyberithub@ubuntu:~/example-app$ git branch
* develop

Then to switch to a new branch master, you need to use git checkout -b master command as shown below.

cyberithub@ubuntu:~/example-app$ git checkout -b master
Switched to a new branch 'master'

 

Step 4: Check for any Latest Changes

Before pulling and merging the files from release branch, check for any latest changes in master using git pull origin master command as shown below.

cyberithub@ubuntu:~/example-app$ git pull origin master
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

From https://app.cyberithub.com/bitbucket/scm/application/example-app.git
* branch            master    -> FETCH_HEAD
Already up to date.

 

Step 5: Pull the Feature Branch Files

Now to pull and merge all the changes from release-1.0.1 branch, we need to use git pull origin release-1.0.1 command as shown below. It should create a new commit in your local system.

cyberithub@ubuntu:~/example-app$ git pull origin release-1.0.1
warning: Pulling without specifying how to reconcile divergent branches is
discouraged. You can squelch this message by running one of the following
commands sometime before your next pull:

git config pull.rebase false # merge (the default strategy)
git config pull.rebase true # rebase
git config pull.ff only # fast-forward only

You can replace "git config" with "git config --global" to set a default
preference for all repositories. You can also pass --rebase, --no-rebase,
or --ff-only on the command line to override the configured default per
invocation.

From https://app.cyberithub.com/bitbucket/scm/application/example-app.git
* branch          release-1.0.1 -> FETCH_HEAD
Merge made by the 'recursive' strategy.
  config/test.yaml  | 2 +-
  config/hello.yaml | 2 +-
  2 Files changed, 4 insertions(+), 4 deletions(-)

 

Step 6: Tag the Commit(Optional)

We can also tag the commit in case it is required by using git tag 1.0.1 HEAD command as shown below. The syntax for tagging the local commit is git tag <release> HEAD.

cyberithub@ubuntu:~/example-app$ git tag 1.0.1 HEAD

After tagging the last commit, you can verify it by using git tag -l command as shown below.

cyberithub@ubuntu:~/example-app$ git tag -l
1.0.1
1.0
0.9
0.8
0.7

 

Step 7: Check the Commit 

You can check all the local commits done using git log command as shown below.

cyberithub@ubuntu:~/example-app$ git log
commit a287db7ea8768baf9fc79369ba318376 (HEAD -> master, tag: 1.0.1)
Merge: b00dccf ea0d6b4
Author: Admin <admin@cyberithub.com>
Date:   Wed Aug 24 16:10:00 2022 +0530

   Merge branch 'release-1.0.1' of https://app.cyberithub.com/bitbucket/scm/application/example-app.git

commit c842ac8e7df8bf9549af9c617b21849 (origin/develop, origin/HEAD, develop)
Merge: b00dccf ea0d6b4
Author: Admin <admin@cyberithub.com>
Date: Wed Aug 23 10:04:00 2022 +0530
.......................................

 

Step 8: Push the Changes to Remote Master Branch

To push all the changes to the remote master branch, we need to use git push -u origin master command as shown below.

cyberithub@ubuntu:~/example-app$ git push -u origin master
Enumerating objects: 16, done. 
Counting objects: 100% (16/16), done. 
Compressing objects: 100% (1/1), done. 
Writing objects: 100% (2/2), 565 bytes | 565.00 KiB/s, done. 
Total 2 (delta 1), reused 0(delta 0), pack-reused 0 
remote: Checking connectivity: 2, done.
remote:
remote: Create pull request for master:
remote: https://app.cyberithub.com/bitbucket/scm/projects/EXAMPLE/repos/example-app/pull-requests?create&sourceBranch=refs/heads/master
remote:
To https://app.cyberithub.com/bitbucket/scm/application/example-app.git
   768ca03..9acb8ca master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

 

Step 9: Checkout to Develop Branch

Now to merge the master branch with develop, we need to first switch to develop branch using git checkout develop command as shown below.

cyberithub@ubuntu:~/example-app$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.

After switching you can verify the current branch by using git branch command as shown below.

cyberithub@ubuntu:~/example-app$ git branch
* develop
  master

 

Step 10: Merge master with develop

Now you can merge the master with develop by using git merge master command as shown below.

cyberithub@ubuntu:~/example-app$ git merge master
Updating b00cbbf..b60607c
Fast-forward
  config/test.yaml        | 2 +-
  config/hello.yaml       | 2 +-
  2 Files changed, 4 insertions(+), 4 deletions(-)

 

Step 11: Push the Changes to Remote Develop Branch

Next step is to push the updated changes from local develop to the remote develop branch using git push -u origin develop command as shown below.

cyberithub@ubuntu:~/example-app$ git push -u origin develop
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://app.cyberithub.com/bitbucket/scm/application/example-app.git
   768ca03..9acb8ca develop -> develop
Branch 'develop' set up to track remote branch 'develop' from 'origin'.

Leave a Comment

error: Content is protected !!