0
0
Gitdevops~30 mins

Ours vs theirs in conflicts in Git - Hands-On Comparison

Choose your learning style9 modes available
Resolving Git Conflicts Using Ours vs Theirs
📖 Scenario: You are working on a team project using Git. Sometimes, when two people change the same file, Git cannot decide which change to keep. This is called a conflict. You will learn how to use ours and theirs strategies to resolve these conflicts.
🎯 Goal: Learn how to create a conflict in Git and resolve it by choosing either your changes (ours) or the other person's changes (theirs).
📋 What You'll Learn
Create a Git repository with two branches
Make conflicting changes in the same file on both branches
Use Git commands to resolve conflicts choosing ours or theirs
Verify the final file content after conflict resolution
💡 Why This Matters
🌍 Real World
In team projects, conflicts happen when multiple people edit the same files. Knowing how to resolve conflicts quickly keeps the project moving smoothly.
💼 Career
Developers and DevOps engineers must handle merge conflicts daily. Mastering <code>ours</code> and <code>theirs</code> helps avoid mistakes and lost work.
Progress0 / 4 steps
1
Create a Git repository and initial file
Initialize a new Git repository called conflict-demo. Create a file named message.txt with the exact content Hello from main branch. Add and commit this file with the message Initial commit on main.
Git
Need a hint?

Use git init to start the repo, echo to create the file, and git add plus git commit to save changes.

2
Create a branch and make conflicting changes
Create a new branch called feature. Switch to it. Change the content of message.txt to Hello from feature branch. Add and commit with the message Update message on feature. Then switch back to main and change message.txt content to Hello from main branch updated. Add and commit with the message Update message on main.
Git
Need a hint?

Use git branch and git checkout to switch branches. Use echo to change file content and commit each change.

3
Merge feature into main and resolve conflict using ours
While on the main branch, run git merge feature to create a conflict. Then resolve the conflict by choosing your version (the main branch) using git checkout --ours message.txt. Add the resolved file and commit with the message Resolve conflict using ours.
Git
Need a hint?

After merge conflict, use git checkout --ours to keep your branch's version, then add and commit.

4
Verify the final content of message.txt
Print the content of message.txt using cat message.txt to verify it shows Hello from main branch updated after resolving the conflict with ours.
Git
Need a hint?

Use cat message.txt to see the file content in the terminal.