Skip to content

Dealing with Merge Conflicts

Matthew Yu edited this page May 5, 2020 · 1 revision

Why are you here?

  • You can't merge a pull request because the branch has conflicts that must be resolved.

Checkout via command line

If you cannot merge a pull request automatically here, you have the option of checking it out via command line to resolve conflicts and perform a manual merge.

Download the repository, if you don't already have it: git clone https://github.com/ut-ras/ras_site.git


Step 1: From your project repository, bring in the changes and test.

git fetch origin
git checkout -b DemobotDancebot origin/DemobotDancebot
git merge master

On git merge master, if you have conflicts, you should see something similar to the following:

matthew@matthew-XPS-15-9560:~/Documents/ras_site$ git merge master 
Auto-merging _posts/2020-05-02-region5.md
Auto-merging .gitignore
CONFLICT (content): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

If you use git status, you should see at the end of the console output the conflicting files:

matthew@matthew-XPS-15-9560:~/Documents/ras_site$ git status
On branch DemobotDancebot
Your branch is up to date with 'origin/DemobotDancebot'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
   ...

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   .gitignore

Looking at the file with the conflicts, we see the following:

cat .gitignore             <- command to show contents of file
_site                      <- start of file output
*.swp
*.icloud
<<<<<<< HEAD               <- beginning of conflict section
*.directory                <- this line belongs to the current branch
=======
.directory                 <- this line belongs to the master branch, and conflicts
>>>>>>> master             <- end of conflict section
.jekyll-metadata

We need to choose one version to use. Delete one branch's output, as follows:

<<<<<<< HEAD
*.directory
=======            --I chose master-->    =======           --cleaning up-->
.directory                                .directory                             .directory
>>>>>>> master                            >>>>>>> master

The final file is as follows:

cat .gitignore             <- command to show contents of file
_site                      <- start of file output
*.swp
*.icloud
.directory                 <- selected change that remains
.jekyll-metadata

After cleaning up all merge conflicted files, run git add [file] on the conflicted file and commit it. Proceed to step 2.


Step 2: Merge the changes and update on GitHub.

git checkout master
git merge --no-ff DemobotDancebot
git push origin master