0
0
Gitdevops~30 mins

Resolving merge conflicts in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Resolving merge conflicts
📖 Scenario: You are working on a team project using Git. Two team members have made changes to the same file, causing a merge conflict. You need to resolve this conflict to keep the project moving smoothly.
🎯 Goal: Learn how to identify, resolve, and complete a merge conflict in Git using command line tools.
📋 What You'll Learn
Create a Git repository with a file named project.txt containing initial content.
Create a new branch called feature and modify project.txt in this branch.
Switch back to main branch and modify project.txt differently.
Attempt to merge feature branch into main and resolve the merge conflict.
Commit the resolved changes and verify the final content.
💡 Why This Matters
🌍 Real World
Merge conflicts happen often when multiple people work on the same code. Knowing how to resolve them keeps projects moving smoothly.
💼 Career
Developers and DevOps engineers must resolve merge conflicts daily to integrate code changes safely and maintain project stability.
Progress0 / 4 steps
1
Create initial Git repository and file
Initialize a new Git repository and create a file named project.txt with the exact content: Initial project setup. Then add and commit this file with the message Initial commit.
Git
Need a hint?

Use git init to start the repo, echo to create the file, then git add and git commit.

2
Create feature branch and modify file
Create a new branch called feature using git branch feature and switch to it with git checkout feature. Then change the content of project.txt to exactly Feature branch update. Add and commit this change with the message Update in feature branch.
Git
Need a hint?

Use git branch and git checkout to switch branches, then edit the file and commit.

3
Modify main branch and attempt merge
Switch back to the main branch using git checkout main. Change the content of project.txt to exactly Main branch update. Add and commit this change with the message Update in main branch. Then attempt to merge the feature branch into main using git merge feature. This will cause a merge conflict.
Git
Need a hint?

Switch back to main, edit and commit the file, then merge feature to see the conflict.

4
Resolve merge conflict and commit
Open project.txt and edit it to contain exactly Resolved content combining main and feature. Then add the file with git add project.txt and commit the merge resolution with git commit -m "Resolved merge conflict". Finally, print the content of project.txt using cat project.txt to verify the final content.
Git
Need a hint?

After editing the file to resolve the conflict, use git add and git commit. Then use cat to show the file content.