25/100 Git Merge Branches

The Nautilus application development team has been working on a project repository /opt/ecommerce.git. This repo is cloned at /usr/src/kodekloudrepos on storage server in Stratos DC. They recently shared the following requirements with DevOps team:

Create a new branch datacenter in /usr/src/kodekloudrepos/ecommerce repo from master and copy the /tmp/index.html file (present on storage server itself) into the repo. Further, add/commit this file in the new branch and merge back that branch into master branch. Finally, push the changes to the origin for both of the branches.

ssh natasha@ststor01
sudo su -
cd /usr/src/kodekloudrepos/ecommerce

# Make sure repo is on master
git branch
* master

# Create new datacenter branch from master branch
git checkout -b datacenter
Switched to a new branch 'datacenter'

# Copy the index html file 
cp /tmp/index.html .

# Stage and Commit the file
git add index.html
git commit -m "Add index html file for datacenter branch"
Add index html file for datacenter branch
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
 
 # Push the datacenter branch to origin
 git push origin datacenter
 Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 349 bytes | 349.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /opt/ecommerce.git
 * [new branch]      datacenter -> datacenter
 
 # Switch back to master branch
 git checkout master
 Switched to branch 'master'
Your branch is up to date with 'origin/master'.

#Merge Datacenter into master
git merge datacenter
Updating e58077a..82a39bf
Fast-forward
 index.html | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
 
 #Push updated master to origin
 git push origin master
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To /opt/ecommerce.git
   e58077a..82a39bf  master -> master

At this point: datacenter branch exists and contains index.html. master also has index.html (after merge). Both branches are pushed to remote (origin).