Skip to content

skills/resolve-merge-conflicts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Resolve merge conflicts

Merge conflicts are a normal part of working in Git. Learn why they happen and how to resolve them with ease.

⛳ Start

start-course

We recommend creating a public repository, as private repositories will use Actions minutes.
After you make your own repository, wait about 20 seconds and refresh. I will go to the next step.

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

  • Who is this for: New developers, new GitHub users, users new to Git, students, managers, teams.
  • What you'll learn: What merge conflicts are, how you resolve merge conflicts, how to reduce merge conflicts.
  • What you'll build: We'll work with a short Markdown resume file in this course.
  • Prerequisites: We recommend taking Introduction to GitHub prior to this course.
  • How long: This course is three steps long and takes less than 30 minutes to complete.
🧘 Step 1: Resolve a merge conflict

Welcome to "Managing Merge Conflicts"! 👋

What is a merge conflict: A Merge conflict occurs when changes are made to the same part of the same file on two different branches. You usually find out about conflicts in a pull request.

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 a new browser tab, and work on the steps in your second tab while you read the instructions in this tab.
  2. Open the pull request we made for you, and we also made a conflict. Have no fear!
  3. At the bottom of the page in the "This branch has conflicts that must be resolved" section of the pull request, click the Resolve conflicts button.
  4. 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.
  5. Remove the changes made on the main branch by deleting all of the content below the ======= and above >>>>>>> main.
  6. Next, remove the merge conflict markers by deleting the following lines:
    <<<<<<< my-resume
    =======
    >>>>>>> main
    
  7. With the merge conflict markers removed, click Mark as resolved.
  8. Finally, click Commit merge.
  9. Wait about 20 seconds then refresh this page for the next step.
😈 Step 2: 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. (Its for educational purposes!)

⌨️ Activity: Create your own conflict

We went ahead and pushed another change to main without updating your my-resume branch in the background.

  1. Click on the Files changed tab in this pull request.
  2. Click in the top right-hand corner of the resume.md file that had been previously modified.
  3. Click Edit file to open the file editor.
  4. Modify the contents of the last line.
  5. Scroll to the bottom of the page and enter a commit message for your change.
  6. Click the Commit changes 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.
:shipit: Step 3: 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!

What's next?


Get help: Post in our community forumReview the GitHub status page

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