Merge conflicts in Git are like traffic jams in a city that promised to be driverless by 2025. They happen, they are annoying, and they will not go away just because you stare at the terminal hard enough. This guide will walk you through detecting, inspecting, resolving, and verifying merge conflicts with real git commands and a pinch of sarcasm to keep you awake.
After a failed git merge
or a rough git pull
run git status
and let Git do the heavy lifting. It will list unmerged paths so you do not play guessing games or consult a crystal ball.
git status
Use git diff
to see the differences and git diff --name-only
to get a short list of affected files. Open the file to see conflict markers that look like a tiny legal dispute inside your source code.
git diff --name-only
# conflict markers inside a file look like this
<<<<<<< HEAD
your changes here
=======
incoming changes here
>>>>>>> feature/branch
git diff
to read changes in the terminal.git mergetool
to launch a visual merge tool for the faint of heart or the attention challenged.git log --merge
when you want to inspect commits involved in the conflict.You have options, none of them involve chanting. Pick the one that fits your situation.
git checkout --ours path
. If you prefer incoming work use git checkout --theirs path
. These are blunt instruments but useful sometimes.git mergetool
. It will show both sides and let you compose the final version.Once you have removed markers and shaped the file, tell Git you are done by staging the files. This is Git s way of nodding and moving on.
git add path/to/resolved_file
# once all files are staged
git commit
Git will usually prepare a merge commit message for you. Keep it honest and short. Your future self will either be grateful or very judgmental.
Run your test suite and a couple of manual checks as needed. Passing tests beat a smug commit message any day. When you are happy push the fixed branch with git push
and share the peace with your team.
git push
git config --global rerere.enabled true
. Git will remember how you resolved similar conflicts earlier and save you time.git status
to find conflictsgit diff
or a merge toolgit checkout --ours
or git checkout --theirs
git add
and commit the mergeResolve conflicts with a little patience and a tiny bit of dignity. Your repository will survive and your teammates will forget what happened, at least until the next feature branch collides with reality.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.