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

Guides

Git Merge Conflicts Step by Step कशी सोडवायच्या

Git merge conflicts: markers वाचा, सत्य ओळी edit करा, git add, commit, log/graph ने verify.

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. Markers पहा.
  2. सत्य edit करा.
  3. git add.
  4. git commit.
  5. 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

Merge conflicts का होतात

main आणि feature वर एकाच ओळीवर दोन जण बदल करतात — Flipkart/Infosys मध्ये सामान्य — तेव्हा Git merge थांबवते.

Why: दोन शाखांवर समान ओळी. What: Git markers टाकते आणि थांबते. How: Reproduce, markers वाचा, सत्य निवडा, 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: Markers पहा

Markers दोन्ही आवृत्त्या दाखवतात.

Why: काहीही मिटवण्याआधी दोन्ही बाजू. What: <<<<<<< HEAD, =======, >>>>>>>. How: फाईल उघडा आणि UU पहा.

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: निवडा किंवा एकत्र करा

--ours, --theirs, किंवा हाताने तिसरे उत्तर.

Why: अंधा ours bugfix गमावू शकतो. What: checkout --ours/--theirs किंवा edit. How: अर्थ महत्त्वाचा असेल तर standup.

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: पूर्ण करा आणि verify

add, commit, नंतर log.

Why: अपूर्ण merge इतर काम अडवते. What: git add, commit, log --graph. How: गोंधळात असाल तर abort.

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 (पाठ करा)

  1. Markers वाचा
  2. सत्य ओळी edit
  3. git add FILE
  4. git commit
  5. git log --graph

Suppose: Infosys payment config

Timeout वर मतभेद. Standup 30s ठरवते. Hand-edit, add, commit.

Suppose: TCS feature PR

लवकर merge. git merge --abort, नंतर बोलून पुन्हा.

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. Conflict markers कसे दिसतात?

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

Q2. git status मध्ये UU म्हणजे?

दोन्ही बाजू बदलले; अजून unresolved

Q3. Edit नंतर कसे पूर्ण करायचे?

git add नंतर git commit

Q4. गोंधळलेला merge कसा रद्द?

git merge --abort

Q5. स्वच्छ merge कशी सिद्ध?

git log --oneline --graph

Q6. नेहमी --ours?

नाही — अनेकदा तिसरे agreed value

Reading tracking

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

Markers → सत्य → add → commit → log --graph. UU फाईल्स सोडू नका. 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.