Skip to content

Learn why conflicts happen and how to resolve them.

License

Notifications You must be signed in to change notification settings

SEIBootcamps/resolve-merge-conflicts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resolve merge conflicts

Learn why conflicts happen and how to resolve them.

Welcome

Merge conflicts happen when two people make changes to the same file on GitHub—a common occurrence when you’re working with others. While resolving differences might involve some discussion, merge conflicts don’t have to be scary. This guides you through the steps to finding the best merge conflict solution, so your team can keep building.

Step 1: Create a pull request

Welcome to "Managing Merge Conflicts"! 👋

You usually find out about conflicts in a pull request so let's start by creating one.

⌨️ Activity: Create a pull request

  1. Open a new browser tab, and work on the steps in your second tab while you read the instructions in this tab.
  2. We made a small change to a file in the repository in the my-resume branch.
  3. Create a pull request setting my-resume as the head branch and main as the base branch. You can enter Resolving merge conflicts for the pull request title and body.
  4. Wait about 20 seconds then refresh this page for the next step.

Step 2: Resolve a merge conflict

Good start! Now let's look deeper at a merge conflict! 🔍

This can be intimidating, but have no fear, Git is smart when it comes to merging! Git only needs a human to decide how to resolve the conflict. Sometimes, the best way to resolve a merge conflict is to add content that's from both branches, or even something that isn't on either! This is why Git needs a human to look at the code and make the proper fixes.

⌨️ Activity: Resolve a merge conflict

  1. Open the pull request that you just created, we created a conflict for you. Have no fear!
  2. At the bottom of the page, under "This branch has conflicts that must be resolved", click the Resolve conflicts button.
  3. Look for the highlighted sections that begins with <<<<<<< my-resume and ends with >>>>>>> main. These markers are added by Git to show you the content that is in conflict.
  4. Remove the changes made on the main branch by deleting all of the content below the ======= and above >>>>>>> main.
  5. Next, remove the merge conflict markers by deleting the following lines:
    <<<<<<< my-resume
    =======
    >>>>>>> main
    
  6. With the merge conflict markers removed, click Mark as resolved.
  7. Finally, click Commit merge.
  8. Wait about 20 seconds then refresh this page for the next step.

Step 3: Create your own conflict

Good job! You've solved a merge conflict! 🎉

Resolving a conflict doesn't automatically merge the pull request in GitHub. Instead, it stores the resolution of the conflict in a merge commit and allows you and your team to keep working. To resolve a conflict, GitHub performs what is known as a reverse merge. This means that the changes from the main branch were merged into your my-resume branch. With a reverse merge, only the my-resume branch is updated. This allows you to test the resolved changes on your branch before you merge it into main.

Now, let's get a little evil. (It's for educational purposes!)

⌨️ Activity: Create your own conflict

We went ahead and added a new file called references.md and pushed that change to main, without updating your my-resume branch.

  1. Browse to the my-resume branch.
  2. Click the Add file dropdown menu and then on Create new file.
  3. Create a file named references.md.
  4. Enter some text that conflicts with what we added for references.md in the main branch.
  5. Scroll to the bottom of the page and enter a commit message for your change.
  6. Click the Commit new file button, making sure the "Commit directly to the my-resume branch" option is selected.
  7. Wait about 20 seconds then refresh this page for the next step.

Step 4: Merge your pull request

Almost there! ❤️

You can now merge your pull request!

⌨️ Activity: Merge your pull request

  1. First, resolve any remaining conflicts in your pull request.

    Look back at step one if you need help.

  2. Click Merge pull request.
  3. Delete the branch my-resume (optional).
  4. Wait about 20 seconds then refresh this page for the next step.

Finish

Congratulations friend, you've completed this course!

celebrate

Here's a recap of all the tasks you've accomplished in your repository:

  • You learned why merge conflicts happen.
  • You resolved a simple merge conflict.
  • You created a merge conflict, and resolved it!

© 2022 GitHub • Code of ConductCC-BY-4.0 License

About

Learn why conflicts happen and how to resolve them.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published