• Skip to main content
  • Skip to after header navigation
  • Skip to site footer

Free-Mail

  • Events
  • Images
    • Instagram Goodness
  • Music
  • News
  • Software

How to resolve Git merge conflicts

How to resolve Git merge conflicts: How to resolve Git merge conflicts agantony Tue, 04/04/2023 – 03:00

Suppose you and I are working on the same file called index.html. I make some changes to the file, commit them, and push the changes to the remote Git repository. You also make some changes to the same file, commit them, and start pushing the changes to the same Git repository. However, Git detects a conflict because the changes you made conflict with the changes I made.

Here’s how you can resolve the conflict:

  1. Fetch and merge the latest changes from the remote repository:

     $   git pull
  2. Identify the one or more conflicting files:

     $   git status
  3. Open the conflicting file using a text editor:

     $   vim index.html
  4. Resolve the conflict. The conflicting changes are marked by <<<<<<< HEAD and >>>>>>>. You need to choose which changes to keep and which to discard. Manually edit the file to combine the conflicting changes. 

    Here's an example:

     <<<<<<< HEAD 

    Sample text 1

    =======

    Sample text 2

    >>>>>>> feature-branch

    In this example, I changed the website heading to Sample text 1, while you have changed the heading to Sample text 2. Both changes have been added to the file. You can now decide which heading to keep or edit the file to combine the changes. In either case, remove the markers that indicate the beginning and end of the changes, leaving only the code you want:

     

    Sample text 2

  5. Save all of your changes, and close your editor.

  6. Add the file to the staging area:

     $   git add index.html
  7. Commit the changes:

     $   git commit -m "Updated h1 in index.html"

    This command commits the changes with the message Resolved merge conflict.

  8. Push the changes to the remote repository:

     $   git push
More on Git
What is Git?
Git cheat sheet
Markdown cheat sheet
New Git articles

Resolution

 Merge conflicts are a good reason to focus your changes on code. The more you change in a file, the greater the potential for conflict. You should make more commits with fewer changes each. You should avoid making a monolithic change that combines multiple feature enhancements or bug fixes into one. Your project manager will thank you, too, because commits with clear intent are easier to track. A Git merge conflict may seem intimidating at first, but now that you know how to do it, you'll see that it's easily resolved.

Don't panic when you encounter a merge conflict. With a little expert negotiation, you can resolve any conflict.

Coding on a computer
Git

What to read next
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.
Register or Login to post a comment.

: Opensource.com agantony

Supporting Open Source.

Have you tried: Farking?

Share this:

  • Share on Facebook (Opens in new window) Facebook
  • Share on X (Opens in new window) X
  • Share on Pinterest (Opens in new window) Pinterest
  • Email a link to a friend (Opens in new window) Email
  • More
  • Share on Tumblr (Opens in new window) Tumblr
  • Print (Opens in new window) Print
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
Published on 4 April 2023 by Alan Category: SoftwareTag: conflicts, merge, resolve

Can the New Google+ Compete With Facebook? – Facebook

Can the New Google+ Compete With Facebook? – Yahoo News snippet curated by WP Robot as being …

Read moreCan the New Google+ Compete With Facebook? – Facebook

Huddled mice could change the way we think about evolution

Huddled mice could change the way we think about evolution: Pixabay Adapt or die. That’s the reality …

Read moreHuddled mice could change the way we think about evolution

Hermanus old whaling station. Now hotel. Wilderness. Garden Route

A cool South African City image: Hermanus old whaling station. Now hotel. Wilderness. Garden Route …

Read moreHermanus old whaling station. Now hotel. Wilderness. Garden Route

About Alan

Previous Post:Easter eggs: their evolution from chicken to chocolate
Next Post:Timeless review: Nigerian star Davido’s new album is mostly form over substance

Reach Trust

Reach Trust is a holding trust for a number of companies within the Stratlec Group.

Copyright © 2026 · Free-Mail · All Rights Reserved · Powered by Straton Electrical

Back to top