Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Dealing with Merge Conflicts | Branching Out: Exploring New Ideas Safely
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Git and GitHub for Absolute Dummies

bookDealing with Merge Conflicts

Imagine you and a friend are writing a story together. You both decide to edit the same sentence, but you each write a different ending. When you try to put your changes together, you realize both endings cannot fit at the same time. This is what happens in Git when two branches change the same part of a file—it's called a merge conflict.

# Here is what a merge conflict might look like in a file:

Once upon a time, there was a brave knight.
<<<<<<< HEAD
He fought dragons and saved the kingdom every day.
=======
She explored the enchanted forest and discovered hidden magic.
>>>>>>> feature/new-ending
The villagers cheered for their hero.

When you try to merge branches and Git finds that both have changed the same lines, it cannot decide which version to keep. Git marks the conflict in the file with special lines: <<<<<<<, =======, and >>>>>>>. The text between <<<<<<< HEAD and ======= is what is currently in your branch. The text between ======= and >>>>>>> feature/new-ending is what came from the branch you are merging in.

To fix a merge conflict, follow these steps:

  1. Open the file and look for the conflict markers: <<<<<<<, =======, and >>>>>>>;
  2. Decide which version you want to keep, or combine the changes in a way that makes sense;
  3. Delete the conflict markers and any unwanted text;
  4. Save the file;
  5. Stage the file with git add;
  6. Commit the resolution with git commit.

Once everything looks good, you tell Git the conflict is resolved by staging and committing the file.

# After resolving the conflict, your file might look like this:

Once upon a time, there was a brave knight.
She explored the enchanted forest and discovered hidden magic.
The villagers cheered for their hero.

# Then you would run:
git add story.txt
git commit -m "Resolved merge conflict in story.txt"

1. What is a merge conflict?

2. How do you fix a merge conflict?

question mark

What is a merge conflict?

Select the correct answer

question mark

How do you fix a merge conflict?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Suggested prompts:

Can you explain what each conflict marker means in more detail?

What should I do if I want to keep parts from both versions?

Are there any tools that can help me resolve merge conflicts more easily?

bookDealing with Merge Conflicts

Swipe um das Menü anzuzeigen

Imagine you and a friend are writing a story together. You both decide to edit the same sentence, but you each write a different ending. When you try to put your changes together, you realize both endings cannot fit at the same time. This is what happens in Git when two branches change the same part of a file—it's called a merge conflict.

# Here is what a merge conflict might look like in a file:

Once upon a time, there was a brave knight.
<<<<<<< HEAD
He fought dragons and saved the kingdom every day.
=======
She explored the enchanted forest and discovered hidden magic.
>>>>>>> feature/new-ending
The villagers cheered for their hero.

When you try to merge branches and Git finds that both have changed the same lines, it cannot decide which version to keep. Git marks the conflict in the file with special lines: <<<<<<<, =======, and >>>>>>>. The text between <<<<<<< HEAD and ======= is what is currently in your branch. The text between ======= and >>>>>>> feature/new-ending is what came from the branch you are merging in.

To fix a merge conflict, follow these steps:

  1. Open the file and look for the conflict markers: <<<<<<<, =======, and >>>>>>>;
  2. Decide which version you want to keep, or combine the changes in a way that makes sense;
  3. Delete the conflict markers and any unwanted text;
  4. Save the file;
  5. Stage the file with git add;
  6. Commit the resolution with git commit.

Once everything looks good, you tell Git the conflict is resolved by staging and committing the file.

# After resolving the conflict, your file might look like this:

Once upon a time, there was a brave knight.
She explored the enchanted forest and discovered hidden magic.
The villagers cheered for their hero.

# Then you would run:
git add story.txt
git commit -m "Resolved merge conflict in story.txt"

1. What is a merge conflict?

2. How do you fix a merge conflict?

question mark

What is a merge conflict?

Select the correct answer

question mark

How do you fix a merge conflict?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 4
some-alt