Open In App
Related Articles

Git Merge and Merge Conflict

Improve Article
Save Article
Like Article

Let us discuss what merging in git. Merging means combining changes from one branch into another branch. Now let’s see how can we perform merging here we can see that we can see one log in the master branch.

Merging Changes

logs in master branch

Now let’s check out the logs in the dev branch and here we can see there are two logs in the dev branch.

Using git logs to see the logs in the dev branch

So now as we can see from the commit present in the dev branch a file k.txt is created which means a file by the name of k.txt is created in the dev branch so now if we want that change to be reflected in the master branch for that we can use the command git merge name_of_the_branch.

Using git merge command

So now we can see that after using the merge command the changes are getting reflected in the master branch and we can see that a new commit is showing up in the git logs of the master branch which is having a commit message a new file k.txt is created.

Seeing git logs in the master branch

Aborting a Merge

So, now let’s see how to abort a merge for aborting a merge we use the command: git merge –abort. Here we can see how we exited from the merging state by using the below command as follows: 

git merge --abort

Using git merge –abort command

Merge with a Commit

On using the simple git merge command it resolves the merge as fast-forward and only updates the branch-pointer but if you want to create a merge commit for that we have to pass –no-ff as a parameter in the below command.

git merge branch_name --no-ff  -m commit_message

Using the git merge command in the  master branch

Here we can say that it is only updating the branch pointer by showing head-on master.

Using git logs to see that on merging changes from the master branch in the bug-fix branch it updates the logs by mentioning the pointer on the  master branch

Here we can see that we have done a merge using a commit successfully

Merge Conflicts

Merge Conflicts are the conflicts that occur when a developer is editing a file in a particular branch and the other developer is also editing that same file or when developer A edits some line of code and that same line of code is being edited by another developer B that leads to conflicts while merging. Now let’s see how to resolve these merge conflicts.

Made some changes in a.txt in master and dev branch

Seeing Merge Conflicts

Steps for Resolving merge Conflicts

From the above procedure, we have successfully resolved our merge conflicts between the two branches and understood the concept of merge conflicts.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Apr, 2022
Like Article
Save Article
Similar Reads