Learn why conflicts happen and how to resolve them.
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 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.
- How long: This course is three steps long and takes less than 30 minutes to complete.
-
Open following URL in browser, click Fork and open the link in a new tab.
https://github.com/fenago/resolve-merge-conflicts
-
In the new tab, follow the prompts to create a new repository.
-
After your new repository is created, wait about 20 seconds, then refresh the page. Follow the step-by-step instructions in the new repository's README.
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.
- Create new branch
my-resume
frommain
branch.
- Select
main
branch and Create a new file calledreferences.md
and pushed that change tomain
, without updating yourmy-resume
branch.
- Browse to the
my-resume
branch. - Click the
Add file
dropdown menu and then onCreate new file
. - Create a file named
references.md
. - Enter some text that conflicts with what we added for
references.md
in themain
branch. - Scroll to the bottom of the page and enter a commit message for your change.
- Click the Commit new file button, making sure the "Commit directly to the
my-resume
branch" option is selected.
- Create new pull request to merge
my-resume
branch into main.
You can now [merge] your pull request!
- First, resolve any remaining conflicts in your pull request.
- Click Merge pull request.
- Delete the branch
my-resume
(optional).
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!