Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Welcome to Managing Merge Conflicts 🎉
Hello, and welcome! If you're here to learn about and practice resolving merge conflicts, you're in the right place.
In this course, you'll learn why merge conflicts happen and solve a few of them. The merge conflicts in this course are simple enough to solve from GitHub.com. But, if you'd prefer, you can solve them using the command line or other local tools.
As an added bonus, the project we are using for this course is a resume hosted on GitHub Pages! So, if you want to keep working after you complete this course, please feel free!
Before starting this course, we recommend completing the Introduction to GitHub Learning Lab first.
How merge conflicts happen
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 knows how to handle this! It only needs a human to decide how to resolve the conflict.
Step 1: Resolve a simple conflict
You may merge a lot of pull requests before you encounter your first merge conflict. That’s because Git is smart when it comes to merging. Unless you're paying close attention to other branches, you won't know about conflicts until you create a pull request.
This branch is a great example. In this scenario, two of our friends have been working in this repository. They both created branches, made changes to the
_config.yml
file, and opened pull requests. One pull request was merged tomain
without problems, but now the other pull request has a conflict.The history of
main
and this branch look something like this:Because this pull request changes the same lines in the
_config.yml
file, there is a merge conflict.Let's help our friends resolve this conflict.
⌨️ Activity: Resolving your first merge conflict
Open your preferred command line interface, which we'll call your shell from now on.
Clone this repository:
Navigate to the repository in your shell:
cd merge-conflicts
Checkout to the
update-config
branch and ensure it is up to date:Merge the
main
branch into theupdate-config
branch. To ensure that you're working with an up to date copy ofmain
, we'll use its remote tracking branch:In Git's response, you'll see the file with the conflict. Open it in your text editor.
Look for the marked hunks that begin with
<<<<<<< update-config
and ends with>>>>>>> main
. These markers are added by Git to show you the content that is in conflict.Remove the changes made on the main branch by deleting all of the content below the
=======
and above>>>>>>> main
.Next, remove the merge conflict markers by deleting the following lines:
Save and close the file. Stage and commit your changes:
Push your merged branches to GitHub:
Watch below for my response.