DevOps Tutorial-2 Resolve merge conflicts in Git and GitHub



In this tutorial we will learn about resolving the merge conflicts in Git and Github. Git can often resolve differences between merged branches. Usually, the changes are on different lines, or even in different files, which makes the merge simple for computers to understand.

However, sometimes there are competing changes that Git needs your help with to decide which changes to incorporate in the final merge. Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve the conflict before you can merge the branches.

Lets discuss this scenario in detail:

1. Generally developers or testers create a new branch and modify the HelloWorld.java in there own branch Fix_Bug01.

Creating a new branch for safely experimenting the changes

Creating a new branch for safely experimenting the changes


Adding a new line

Adding a new line


2. During the same time if another team member modify the same file and same lines in the master branch in the Github Repository.
Updating the File in Github master branch

Updating the File in Github master branch


Committing the changes

Committing the changes


3. In Local Repository if the master branch is refreshed from Global Repository and try to merge these changes in the branch Fix_Bug01 which introduces the merge conflicts.
Refresh the Master

Refresh the Master


Conflicts due to changes in the same file and same line

Conflicts due to changes in the same file and same line


4. Fixing the merge Conflicts by ignoring the lines which are not required.
Merge Conflicts

Merge Conflicts

Deleted the unnecessary lines of code

Deleted the unnecessary lines of code


5. Execute the below commands in the Git bash to resolve the merge conflict.
git status

git add

git commit -m "Commit Message"

Fixing the merge conflicts

Fixing the merge conflicts

Conclusion:

In this example we have learnt how to resolve the merge conflicts in Github and Git.

Leave a Reply

Your email address will not be published. Required fields are marked *