Skip to content

Instantly share code, notes, and snippets.

@lindacmsheard
Created December 3, 2020 20:08
Show Gist options
  • Save lindacmsheard/c7793395b03e1d2c338946d73fce5cc9 to your computer and use it in GitHub Desktop.
Save lindacmsheard/c7793395b03e1d2c338946d73fce5cc9 to your computer and use it in GitHub Desktop.
Dealing with merge conflicts in Git - the short and simple explanation

Dealing with merge conflicts

Merge conflicts are not scary. Any good text editor like VSCode for example will help with buttons and visualisations of what you need to do. But here's the gist...

When a merge conflict occurs, git will actually insert some lines in the file to mark the spot and show both versions of lines that are conflicting:

<<<<<<< HEAD
my current text in the file
=======
someone's changed the same line
>>>>>>>

So, find any file that has some <<< markers in it, and then delete all lines that shouldn't be in the file when we're finished.

To ensure that the merged version has your changes, delete all lines except yours, including the markings. So the block shown above becomes:

my current text in the file

To allow the incoming changes to overwrite your changes, delete everything except that:

someone's changed the same line

Or come to a compromise, and just replace the whole block

we've come to a consensus

Then, just save the file, and when all conflicts have been resolved, do another commit.

git add .
git commit -m 'resolved the conflicts'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment