How to Resolve Merge CONFLICT in Git

Share via:

Dear Readers,

In this article,we will see How to Resolve Merge CONFLICT in Git.

Implementation Steps

  1. Create a new file “ktexperts-1” and put some content.
  2. Add and commit the file “ktexperts-1”.
  3. Switch to branch “Ktexperts-New-Branch”.
  4. Create a new file with same name “ktexperts-1”.
  5. Add and commit the file “ktexperts-1”.
  6. Switch to branch “master”.
  7. Merge commits from branch “Ktexperts-New-Branch” to branch “master”.
  8. Resolve Merge Conflicts.
  9. Push commits from Local Repository  to central repository.
  10. Verify file in central repository.

Git Merge CONFLICT

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits.

A merge conflict occurs when two branches you’re trying to merge both changed the same part of the same file.

When this happens, Git won’t be able to figure out which version to use.

If you have a merge conflict on the command line, you cannot push your local changes to GitHub until you resolve the merge conflict locally on your computer. If you try merging branches on the command line that have a merge conflict, you’ll get an error message.

To see the current branch

Create a new file “ktexperts-1” and put some content

To see the status of git

Add and commit the file “ktexperts-1”

Adding file to staging area

Commit the file into Local Repository

To see the latest commit

Switch to branch “Ktexperts-New-Branch”

Create a new file with same name “ktexperts-1”

To see the status of git

Add and commit the file “ktexperts-1”

Adding file to staging area

Commit the file into Local Repository

To see the latest commit

Switch to branch “master”

To see the branch

Merge commits from branch “Ktexperts-New-Branch” to branch “master”

If you have a merge conflict on the command line, you cannot push your local changes to GitHub until you resolve the merge conflict locally on your computer. If you try merging branches on the command line that have a merge conflict, you’ll get an error message.

When the conflicted line is encountered, Git will edit the content of the affected files with visual indicators that mark both sides of the conflicting content. These visual markers are

  • <<<<<<<– Conflict marker, the conflict starts after this line.
  • ======= – Divides your changes from the changes in the other branch.
  • >>>>>>> – End of the conflicted lines.

Note 

Now when we try to merge our new branch with master, we will create a merge conflict.

Merge conflicts must be resolved before we can continue.

Resolve merge CONFLICT

Open and modify the file “ktexperts-1”

To see the content of file “ktexperts-1”

To see the status of git

Add and commit the file “ktexperts-1”

Adding file to staging area

Commit changes into Local Repository

To see content of file “ktexperts-1”

Push commits from Local Repository  to central repository

Verify file in Central Repository

Go inside your GitHub and hit refresh of your browser.

we can see file”ktexperts-1″and commit message.

To check data of the file

Click on ktexperts-1 to open

We can the content  of file “ktexperts-1”.

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Follow Me
Ramesh’s Linkedin : https://www.linkedin.com/in/ramesh-atchala/

 

 

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

2 thoughts on “How to Resolve Merge CONFLICT in Git

Add Comment