Open In App

Git Merge and Merge Conflict

Last Updated : 05 Apr, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.


Similar Reads

Difference Between Git remote prune, Git prune and Git fetch --prune
One of the great things about Git is that it's *very careful about deleting data*. This makes it pretty hard to lose commits or other valuable data in Git! A small downside of this is that you might sometimes see stale data that you actually don't need anymore. One of the best examples of this is references to remote branches that have already been
2 min read
Difference between “git add -A” and “git add”
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It is basically, software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Featu
3 min read
Git - Difference Between Git Revert, Checkout and Reset
While Working with Git in certain situations we want to undo changes in the working area or index area, sometimes remove commits locally or remotely and we need to reverse those changes. There are 3 different ways in which we can undo the changes in our repository, these are git reset, git checkout, and git revert. git checkout and git reset in fac
7 min read
Difference Between Git Fetch and Git Pull
Understanding the difference between git fetch and git pull is important for effective version control in Git. These commands are important for managing your repository and collaborating with team members. In this article, Let us look at Git Fetch and Git Pull separately with the help of an example. What is Git Fetch?The Git Fetch command is used t
4 min read
Difference Between Git Push Origin and Git Push Origin Master
Understanding the difference between git push origin and git push origin master is important for efficient version control in Git. These commands are used to upload changes from your local repository to a remote repository, but they function differently. This article will explain these differences, how each command works, and when to use them. What
3 min read
Git - git-show Command Line Utility
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it that may be
3 min read
Git LFS: Managing Large Files in Git Repositories
Git, undoubtedly one of the most popular version control systems, is widely used for managing source code in software development projects. However, one of its limitations is its handling of large files. Traditional Git repositories struggle to efficiently manage large files, leading to bloated repositories and slow performance. This is where Git L
4 min read
Git Subtree vs. Git Submodule
Git Subtree and Git Submodule are both mechanisms in Git that allow you to incorporate external repositories into your own repository. They provide a way to manage dependencies and include code from other projects while keeping your repository organized and maintainable. Git Subtree: Git Subtree allows you to insert a separate repository as a subdi
4 min read
How to Set Up Git Using Git Config?
Git is a powerful version control system that helps developers manage and track changes in their code. Setting up Git correctly is important for maintaining an organized and efficient workflow. In this article, we'll walk you through the process of setting up Git using the git config command. PrerequisitesBefore we dive into the setup process, make
3 min read
Git - git prune
In version control systems, Git has powerful features and flexibility. However, as projects evolve and repositories grow, managing Git's internal database becomes important. Enter git prune, a command designed to help you keep your repository lean and clean by removing unreachable or dangling objects. In this article, we'll explore the git prune co
5 min read
Article Tags :