Skip to content

Instantly share code, notes, and snippets.

@slugbyte
Last active February 25, 2016 17:35
Show Gist options
  • Save slugbyte/1904d9ddf24de9476df9 to your computer and use it in GitHub Desktop.
Save slugbyte/1904d9ddf24de9476df9 to your computer and use it in GitHub Desktop.

Handling Merge Conflicts

Issue

  • Some one on your project has merged a Pull Request into the master branch.
  • You push your code to your remote branch named branch_name and open a Pull Request to the master branch.
  • GitHub informs you your code can not automaticly merge into the master branch.

make an overview

Step by Step Solution

  1. Navigate to your project in your shell (the command line).
  • $ cd /path/to/your/project
  1. Make sure you are in the correct branch.
  • $ git branch
    git will list local branches and put a * infront of the branch you are in
  1. Make sure you have notthing to commit. If you have un commited changes, commit them.
  • $ git status
    nothing to commit, working directory clean
  1. Update local copy of origin repository
  • $ git fetch origin
  1. Merge local copy of origin/master into your local branch called branch_name.
  • $ git merge origin/master
    git will tell you what files have failed to automaticly merge
  1. Open the files with conflicts in your text editor.
  2. In each file with conflict delete the code that is unwanted.
  3. In each file Update the code to reflect the correct changes.
  • Delete the lines that say <<< HEAD, ====, and >>> master
  • Delete lines from master or your branch_name that are unwanted.
<<<<<<<<<<< HEAD 
 this is where the conflicting code from your branch is
===========
 this is where the conflicting code from the master branch is
>>>>>>>>>>> master 
  1. RUN YOUR CODE.
  • This is possibly the most important step!
  • Just becuse you "handled" your merge conflict does not mean your haven't broken your app.
  1. Add your changes and commit.
  • $ git add .
  • $ git commit -m "handled merge conflict from master"
  1. Push to your branch_name on origin.
  • $ git push origin <branch_name>
  1. Your Pull Request should be able to merge!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment