Guides
Git Merge Conflicts Step by Step कैसे सुलझाएँ
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
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.
मित्रांनो, conflict markers अपयश नाहीत — नकाशा आहेत. Chala mitrano — दोन्ही बाजू वाचा, सत्य ठेवा, मग commit.
मित्रों, conflict markers असफलता नहीं — नक्शा हैं। Chala mitrano — दोनों पक्ष पढ़ें, सच रखें, फिर commit।
Quick answer
Hold this vertical picture:
- Markers देखें।
- सच edit करें।
- git add।
- git commit।
- git log --graph।
Language: English · मराठी · हिंदी
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:
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:
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:
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 (याद करें)
- Markers पढ़ें
- सही पंक्तियाँ edit
- git add FILE
- git commit
- 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.
Infosys आणि TCS मध्ये reviewers स्वच्छ merge commit message आणि push आधी git log --oneline --graph अपेक्षा करतात.
Infosys और TCS में reviewers साफ़ merge commit message और push से पहले git log --oneline --graph की उम्मीद करते हैं।
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.