0
0
Gitdevops~30 mins

Merge conflicts why they happen in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Why Merge Conflicts Happen in Git
📖 Scenario: You are working on a team project using Git. Two team members make changes to the same file but in different branches. You want to understand why Git sometimes cannot automatically combine these changes and shows a merge conflict.
🎯 Goal: Learn how to create a simple Git repository, make changes in two branches that cause a merge conflict, and observe the conflict message Git shows.
📋 What You'll Learn
Create a Git repository with a file named notes.txt containing specific text
Create a branch named feature and modify notes.txt in it
Switch back to main branch and modify the same line in notes.txt
Attempt to merge feature branch into main and observe the merge conflict message
💡 Why This Matters
🌍 Real World
Merge conflicts happen often when multiple people work on the same files in a project. Understanding why they happen helps you fix them quickly.
💼 Career
Developers and DevOps engineers must handle merge conflicts daily to keep code working smoothly and avoid losing work.
Progress0 / 4 steps
1
Create initial Git repository and file
Initialize a Git repository and create a file named notes.txt with the exact content: Hello from main branch. Then add and commit this file.
Git
Need a hint?

Use git init to start the repo. Use echo to write text to notes.txt. Then add and commit the file.

2
Create and switch to feature branch, modify file
Create a new branch called feature and switch to it. Then change the content of notes.txt to Hello from feature branch. Add and commit this change.
Git
Need a hint?

Use git checkout -b feature to create and switch branches. Then modify the file and commit.

3
Switch back to main branch and modify file
Switch back to the main branch. Change the content of notes.txt to Hello from main branch updated. Add and commit this change.
Git
Need a hint?

Use git checkout main to switch back. Then modify and commit the file.

4
Attempt to merge feature branch into main and observe conflict
Run the command to merge the feature branch into main. Observe the output message that shows a merge conflict in notes.txt.
Git
Need a hint?

Use git merge feature to merge the feature branch into main. Git will show a conflict message.