Ravindra BagaleCourses & study guides मराठी Track your progress

Guides

How to Resolve Git Merge Conflicts Step by Step

Resolve Git merge conflicts by reading markers, editing the true lines, git add, commit, then verify with log and graph.

Friends, conflict markers are not failure — they are a map. Chala mitrano — read both sides, keep the truth, then commit.

Quick answer

Hold this vertical picture:

  1. See conflict markers in the file.
  2. Edit and delete the marker lines.
  3. git add the resolved file.
  4. git commit to finish the merge.
  5. Verify with git log --graph.

Language: English · मराठी · हिंदी

Pull or mergeTwo edits meet See markers<<<<<<< ======= >>>>>>> Edit the fileKeep the right lines git addMark resolved git commitFinish the merge Verifylog and diff
Merge conflict path

Why merge conflicts happen

When two people edit the same line on main and a feature branch — common at Flipkart and Infosys — Git pauses the merge and asks you to choose.

Why: Same lines changed on two branches. What: Git inserts conflict markers and stops the merge. How: Reproduce, read markers, pick truth, finish commit.

Example 1: Start a lab repo

Type this:

mkdir -p /tmp/merge-lab && cd /tmp/merge-lab && git init -b main && git config user.email lab@example.com && git config user.name Lab && printf '%s\n' 'color=red' > app.cfg && git add app.cfg && git commit -m 'base config'

You will see:

[main (root-commit) ...] base config

What it means: A tiny repo with one config file — same pattern as a Flipkart service config.

Example 2: Make a feature branch change

Type this:

cd /tmp/merge-lab && git checkout -b feature/color && printf '%s\n' 'color=blue' > app.cfg && git add app.cfg && git commit -m 'feature wants blue'

You will see:

[feature/color ...] feature wants blue

What it means: Feature branch changed color to blue.

Example 3: Change main differently

Type this:

cd /tmp/merge-lab && git checkout main && printf '%s\n' 'color=green' > app.cfg && git add app.cfg && git commit -m 'main wants green'

You will see:

[main ...] main wants green

What it means: Main changed the same line — conflict is guaranteed on merge.

Concept 1: See the markers

Markers wrap both versions so you can compare.

Why: You must see both sides before deleting anything. What: <<<<<<< HEAD, =======, >>>>>>> branch. How: Open the file and status UU paths.

Example 4: Merge and see conflict

Type this:

cd /tmp/merge-lab && git merge feature/color || true && sed -n '1,20p' app.cfg

You will see:

<<<<<<< HEAD
color=green
=======
color=blue
>>>>>>> feature/color

What it means: Markers show both sides. HEAD is your current branch (main).

Example 5: List unmerged paths

Type this:

cd /tmp/merge-lab && git status --short

You will see:

UU app.cfg

What it means: UU means both sides modified — still unresolved.

Concept 2: Choose or combine

Use --ours, --theirs, or a hand-written third result.

Why: Blind keep-ours can drop a needed bugfix. What: checkout --ours/--theirs or edit by hand. How: Agree in standup when product meaning matters.

Example 6: Keep main (ours) with checkout

Type this:

cd /tmp/merge-lab && git checkout --ours app.cfg && cat app.cfg

You will see:

color=green

What it means: --ours keeps the current branch version during a merge.

Example 7: Or keep feature (theirs)

Type this:

cd /tmp/merge-lab && git checkout --theirs app.cfg && cat app.cfg

You will see:

color=blue

What it means: --theirs keeps the branch you merged in. Pick one truth for the team.

Example 8: Hand-edit a combined result

Type this:

cd /tmp/merge-lab && printf '%s\n' 'color=teal' 'note=agreed-in-standup' > app.cfg && cat app.cfg

You will see:

color=teal
note=agreed-in-standup

What it means: Often the real fix is a third value the team agreed — not blind ours/theirs.

Concept 3: Finish and verify

add, commit, then prove with log and status.

Why: An unfinished merge blocks other work. What: git add, git commit, git log --graph. How: Abort only when you are lost and want a clean slate.

Example 9: Mark resolved and commit

Type this:

cd /tmp/merge-lab && git add app.cfg && git commit -m 'merge feature/color: teal after standup' && git status

You will see:

On branch main
nothing to commit, working tree clean

What it means: add + commit finishes the merge. Status must be clean.

Example 10: Verify with log graph

Type this:

cd /tmp/merge-lab && git log --oneline --graph --decorate -n 5

You will see:

*   ... merge feature/color: teal after standup
|\
| * ... feature wants blue
* | ... main wants green

What it means: Graph proves both histories joined. Say this in Accenture interviews.

Example 11: Abort a bad merge mid-way

Type this:

cd /tmp/demo-abort 2>/dev/null; mkdir -p /tmp/demo-abort && cd /tmp/demo-abort && git init -b main >/dev/null && git config user.email a@example.com && git config user.name A && printf 'x\n' > f && git add f && git commit -m b >/dev/null && git checkout -b o && printf 'y\n' > f && git commit -am o >/dev/null && git checkout main && printf 'z\n' > f && git commit -am m >/dev/null && git merge o || true; git merge --abort && git status --short

You will see:

(clean or empty short status)

What it means: git merge --abort returns you to pre-merge state when confused.

Example 12: Conflict card to memorize

Type this:

printf '%s\n' '1 see markers 2 edit truth 3 git add 4 git commit 5 git log --graph'

You will see:

1 see markers 2 edit truth 3 git add 4 git commit 5 git log --graph

What it means: Use this card on every Netflix-style service PR conflict.

Conflict card (memorize)

  1. Read <<<<<<< ======= >>>>>>>
  2. Edit the true lines (delete markers)
  3. git add FILE
  4. git commit (merge message)
  5. git log --oneline --graph

Suppose: Infosys payment config

Two teams change the same timeout. Standup agrees 30s. Hand-edit, add, commit.

Suppose: TCS feature PR

You merged too early. git merge --abort, rebase or re-merge after talking.

Ravindra Bagale's Tip

At Infosys and TCS, reviewers expect a clean merge commit message and a quick git log --oneline --graph check before you push.

Check yourself (quiz)

Q1. What do conflict markers look like?

<<<<<<< HEAD, =======, and >>>>>>> other-branch

Q2. What does UU mean in git status?

Both sides modified; still unresolved

Q3. How do you finish after editing?

git add the file, then git commit

Q4. How do you cancel a confused merge?

git merge --abort

Q5. What verifies a clean merge history?

git log --oneline --graph

Q6. Should you always use --ours?

No — often the team needs a combined third value

Reading tracking

Mark this guide when you finish. Your browser remembers it on this device.

Markers → edit truth → add → commit → log --graph. Never leave UU files. Did you understand? Let us try it once more.

Frequently asked questions

What are conflict markers?

<<<<<<< HEAD, =======, and >>>>>>> branch-name lines Git inserts.

What does UU mean?

Both sides modified; the path is still unresolved.

How do you finish a conflict?

Edit the file, git add, then git commit.

How do you cancel a merge?

git merge --abort

When is --ours wrong?

When the other branch has the bug fix you need.

What do reviewers check?

Clean message and git log --oneline --graph.