Resolve Merge Conflict in The GitHub Repository — Git Case Study 2
Problem Statement:
You work for Zendrix Software & Co. You have been assigned the task of updating the master branch of their Git repository with all the features from the feature branches.
Following is the GitHub account:
https://github.com/devops-intellipaat/merge-conflict.git
Consider:
● Feature1 branch to be a public branch
● Feature2 branch to be a private branch
The company relies on a monolithic architecture and for now all the code resides in one file “main.c”.
The respective features have been added in the feature branches for main.c. Meanwhile, a security patch was made to the master branch, and now feature1 and feature2 branches are behind from master by 1 commit.
Tasks to Be Performed:
1. Update Feature1 and Feature2 branch with the Security Patch
2. Apply changes of Feature1 and Feature2 branches on master
3. Finally push all the branches to GitHub
For solving this, please fork the repository to your GitHub account and then work. As a solution, please submit your GitHub’s repository link
Note: Here, Security Patch means software & operating system updates that aims to fix security vulnerabilities in a program or product.
Before moving this case study solution, if you have not checked the Git assignments, please check out these Git Assignment Solutions:
Create The Files & Push them to Git Hub Repository — Git Assignment 1
Create the Files in Separate Branches And Perform Stash & Unstash Operations — Git Assignment 2
Create & Delete the Branches in Git Hub from Local & Remote Repository — Git Assignment 3
Create Two Branches & Merge These Branches to the Master Branch — Git Assignment 4
Create a Git Workflow Architecture & Use Hotfix to Push a File — Git Assignment 5
Suggested a Git Workflow Architecture to Manage the Product Release — Git Case Study 1
Check the Git Hub Repository for this Assignment to Copy the Commands:
Problem (1) & (2) Integrated Solution:
Update Feature1 and Feature2 branch with the Security Patch
Apply changes of Feature1 and Feature2 branches on the master
Follow these steps:
A. Create an EC2 Instance to Perform the Case Study
Step 1: Step 1: Go to the “Services” section & search “EC2” here. Put the cursor over “EC2” & click on “Instances” here.
Step 2: Click on “Launch Instances”.
Step 3: Choose “Name” as “Git-Case-Study-2” in the “Name and tags” section.
Step 4: Choose “AMI” as “ubuntu”.
Step 5: Choose “Instance type” as “t2.micro”.
Step 6: Choose “key pair (name) — required” as “Demo”.
Step 7: In the “Network Settings”, choose “Select existing security group” in the “Firewall (security groups)” & while choosing the “Common security groups” as “launch-wizard-9”.
Step 8: Click on “Launch Instance” in the “Summary” section.
Step 9: The “Instance” will be successfully launched, click on “hyperlink (i-0f7c6e67b4674acfe).
Step 10: The “Instance [Git-Case-Study-2]” will be in the “Running” State.
Step 11: Select the Instance & Click on “Connect”.
Step 12: Again, click on “Connect”.
Step 13: First, update the machine using the below-given command:
sudo apt-get update
Step 14: The machine will be successfully updated.
B. Fork the Given GitHub Repository from the Problem Statement
Step 1: First, Sign in to the “Git Hub” account. Go to the “github.com” homepage & click on “Sign in”.
Step 2: Click on “Sign-in”.
Step 3: Your “Git Hub Account” has been successfully logged in.
Step 4: Copy the given link from the above problem statement & paste it into the browser address bar. The given “Git Hub” repository will be successfully opened.
Step 5: Fork this repository using the “fork” button.
Step 6: Put the “merge-conflict” in the description & select the given option: Copy the “master” branch only.
Click on “Create fork”.
Step 7: The given repository “merge-conflict” has been successfully forked.
C. Clone the Given GitHub Repository on Git Hub Local
Step 1: Use the below-given command to clone the repository:
git clone https://github.com/visaltyagi/merge-conflict.git
Step 2: The repository will be successfully cloned.
D. Check All Branches
Step 1: Run the below-given command here & it will show the “merge-conflict” folder.
ls
Go to the “merge-conflict” folder using the below-given command:
cd merge-conflict
Step 2: Type the below-given command to check the branch:
git branch
Only the “master” branch will be shown.
Step 3: Run these below-given commands to check out all the branches:
git checkout feature1
git checkout feature2
Step 4: Now, all the branches will be shown. Type the below-given command again:
git branch
E. Merge All the Branches to the Git Hub “master” Repository
Step 1: Run the below-given command to check out the “master” repository:
git checkout master
Step 2: When we run the below-given command, it shows the “conflicts” message.
git merge feature2
Step 3: Run the below-given command to check out the “merge conflict” resolution tool:
git mergetool --tool=
Step 4: Press “enter” from the keyboard & the “vimdiff” tool will be opened.
Step 5: Press “ESC” from the keyboard & type the below-given command to save & quit from all the files one by one:
:wq!
Press “enter” from the keyboard to completely save & exit from the files after running the :wq! command every time.
Step 5: The files have been successfully edited & merge conflict has been resolved.
Step 6: Open the main.c file using the below-given command:
sudo nano main.c
Step 7: Remove the unwanted code from here:
Step 8: Now, run the below-given command to check the status of files:
git status
Step 9: Run the below-given command to add the “main.c” file:
git add .
Step 10: Run the below-given command to commit changes:
git commit –m "first commit"
Step 11: Now, we will merge the “feature2” branch into the “master” branch. Run the below-given command first:
git merge feature2
Step 12: Run the below-given command to open the “vimdiff” editor:
git mergetool --tool=vimdiff
Step 13: Press “ESC” from the keyboard & type the below-given command to save & quit from all the files one by one:
:wq!
Press “enter” from the keyboard to completely save & exit from the files after running the :wq! command every time.
Step 14: All the files will be successfully merged. It means the “feature2” branch code will be successfully merged into the “master” branch.
Step 15: Open the “main.c” file using the below-given command in the master:
sudo nano main. c
Step 16: Remove the unwanted lines from the “main.c” file.
Do “CTRL+X” to exit & press “Y” to save the file. Press “enter” from the keyboard to completely exit from the “main.c” file.
Step 17: Run the below-given command to add the untracked changes:
git add .
Step 18: Save all the changes using the below-given command:
git commit –m "Second Commit"
Problem (3) Solution: Finally push all the branches to GitHub
Step 1: Type the below-given command to add the repository to “Git Hub Local”:
git remote add merge-conflict https://github.com/visaltyagi/merge-conflict.git
Step 2: Check repository is added or not, use the below-given command:
git remote –v
It will be successfully fetched in the repository.
Step 3: Run the below-given command to delete the “main.c.orig” file:
sudo rm -r main.c.orig
Step 4: Run the below-given command to push all the changes to the “Git Hub” master branch:
git push merge-conflict master
Put the username & password here.
We will put the username as our “Git Hub Account” username & password as “Git Hub Token”.
The “master” branch changes will be successfully pushed.
Step 5: All the changes will be successfully pushed to the “master” branch in “Git Hub Remote Repository”.
Step 6: Open the “main.c” file, all new changes will be shown.
Other Devops Case Studies:
Containerized an HTML Website using Docker on Production Environment — Docker Case Study
Creating an Architecture using Terraform on AWS — Terraform Case Study
Integration of DevOps Tools with Jenkins — Jenkins Case Study
How to Deploy a Sample Website on Kubernetes Using Ingress — Kubernetes Case Study