in Technology by

What is a merge conflict in Git, and how can it be resolved?

1 Answer

0 votes
by

Manually edit the conflicted file to select the changes that you want to keep in the final merge.

Resolve using GitHub conflict editor

This is done when a merge conflict is caused after competing for line changes. For example, this may occur when people make different changes to the same line of the same file on different branches in your Git repository.

Resolving a merge conflict using conflict editor:

Under your repository name, click "Pull requests."

In the "Pull requests" drop-down, click the pull request with a merge conflict that you'd like to resolve

Near the bottom of your pull request, click "Resolve conflicts."

 

Decide if you only want to keep your branch's changes, the other branch's changes, or make a brand new change, which may incorporate changes from both branches.

Delete the conflict markers <<<<<<<, =======, >>>>>>> and make changes you want in the final merge.

If you have more than one merge conflict in your file, scroll down to the next set of conflict markers and repeat steps four and five to resolve your merge conflict.

Once you have resolved all the conflicts in the file, click Mark as resolved.

If you have more than one file with a conflict, select the next file you want to edit on the left side of the page under "conflicting files" and repeat steps four to seven until you've resolved all of your pull request's merge conflicts.

Once you've resolved your merge conflicts, click Commit merge. This merges the entire base branch into your head branch.

To merge your pull request, click Merge pull request.

A merge conflict is resolved using the command line.

Open Git Bash.

Navigate into the local Git repository that contains the merge conflict.

Generate a list of the files that the merge conflict affects. In this example, the file styleguide.md has a merge conflict.

Git Status

Open any text editor, such as Sublime Text or Atom, and navigate to the file that has merge conflicts.

To see the beginning of the merge conflict in your file, search the file for the conflict marker "<<<<<<<. " Open it, and you'll see the changes from the base branch after the line "<<<<<<< HEAD."

Next, you'll see "=======", which divides your changes from the changes in the other branch, followed by ">>>>>>> BRANCH-NAME".

Decide if you only want to keep your branch's changes, the other branch's changes, or make a brand new change, which may incorporate changes from both branches.

Delete the conflict markers "<<<<<<<", "=======", ">>>>>>>" and make the changes you want in the final merge.

        In this example, both the changes are incorporated into the final merge:

Add or stage your changes. 

Commit your changes with a comment.

Now you can merge the branches on the command line, or push your changes to your remote repository on GitHub and merge your changes in a pull request.

Related questions

0 votes
    I used git pull and had a merge conflict: unmerged: _widget.html.erb You are in the middle of a conflicted merge. ... can I do this? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How can we abort the merge if there is a merge conflict?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    What is a conflict in Git and how to resolve it?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    How to resolve a conflict in Git?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    As asked in this question, I also want to know how to resolve a conflicting git stash pop without ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    The below image shows my question in detail: it works when client version is changed to 5 beta but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    The process by which different equivalent forms of a name can be resolved to a single standard name, (1)Canonicalization (2)Aliasing (3)Name resolution (4)Input resolution...
asked May 13, 2021 in Technology by JackTerrance
0 votes
    How to Undo a Git merge that hasn't been pushed yet?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How to resolve merge conflicts in Git repository?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    What is the difference between Git Merge and Git Rebase?...
asked Oct 4, 2020 in Technology by Editorial Staff
0 votes
    I have an old, out-of-sync project code in the master branch. Several files have been deleted, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am just getting started towards android and i am having trouble with my hello world app, The problem ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I installed pygame using the pip in command prompt but it still shows an error. I have already attempted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    The entity that normally is supposed to determine whether an academic researcher's conflict of interest can be managed is:...
asked Nov 29, 2020 in Technology by Editorial Staff
0 votes
    If I want to use the validation framework that you can use with ASP.NET MVC, will the JavaScript ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
...