# 13. How to solve merge conflicts?
Since working with Github allows multiple developers to work in parallel,
each on their copy of the repository, merge conflicts may occur when two developers change the same file and try to upload the changes to the central repo.
The way to solve the problem is by pulling the updated version from the central repository, updating the file with your changes, and pushing it back to github.com.
Merge conflict occurs when two developers change the same line in the same file, or when a developer deletes a file.
To simulate the problem download a second copy of the "exploring_git" repo to your computer, and place it in a different folder "exploring_git2".
If you can't remmember how to clone the repo read the previous section of this tutorial how to clone a remote repo.
cd into the local repo:
$ cd exploring_git2/exploring_git
Edit the "index.php" file by changing the content of the $x variable:
index.php
<?php
$x = 'Welcome to the Git and Github essentials for web developers and programmers repo';
Upload the changes that you have made in the second copy of the repo to github.com
$ git add -A
$ git commit -m "First commit from the second copy"
$ git push
***
Now get out of the second copy of the repo and cd into the first copy:
$ cd exploring_git
Try to change the same line then upload to the remote repo:
index.php
<?php
$x = 'Changes in the same line from the first repo';
$ git add -A
$ git commit -m "New upload from the original repo"
$ git push
The result might not be what you expect:
To https://github.com/[your_username]/exploring_git.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/[your_username]/exploring_git.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
What you see is a merge conflict in action.
To solve the problem do the following:
- Pull the remote repo:
$ git pull
With the result:
From github/[your_username]/exploring_git
* branch master -> FETCH_HEAD
Auto-merging index.php
CONFLICT (content): Merge conflict in index.php
Automatic merge failed; fix conflicts and then commit the result.
- Open the "index.php" file and you will see something like this:
<?php
<<<<<<< HEAD
$x = 'Changes in the same line from the first repo.';
=======
$x = 'Welcome to the Git and Github essentials for web developers and programmers repo';
>>>>>>> 74934dd8ca1dc11dccccd98671d51e945c68f2f9
The first line is from the current repo and the second from the other repo.
- To resolve the conflict, decide which code to delete or merge the two versions.
<?php
$x = 'the merged line';
After you solved the problem, commit the merged file to Github as already explained.