Is there a simple git command that can tell (e.g. by exit status) whether a work tree has unmerged paths / a merge conflict? Like when a git merge operation fails and git returns to the shell and git status shows that there are merge conflicts.
I found so far git status and a list of values it would output in an unmerged situation (the XY status codes then):
X Y Meaning ------------------------------------------------- D D unmerged, both deleted A U unmerged, added by us U D unmerged, deleted by them U A unmerged, added by them D U unmerged, deleted by us A A unmerged, both added U U unmerged, both modified ------------------------------------------------- So that the only way to detect so for me so far would be to match against a list of XY codes that represent unmerged, e.g.:
AA | DD | [ADU]U | U[AD] (added horizontal white space for readability)
A check with zero exit status in case of unmerged paths (or non-zero if none) then would be (if my understanding of git status is correct here):
git status --porcelain -z \ | grep -q -z '^\(AA\|DD\|[ADU]U\|U[AD]\) ' This becomes rather convoluted and I'm looking for a more simple command (best with git only).
I want to use it in bash script for a local build that rejects further processing if there are any unmerged paths in the git repositories work tree.
git checkout -m, a checkout operation never merges anything and therefore never produces a merge conflict. (You havecheckoutspecifically in your question title/subject.) The only way you could have a merge conflict for such an operation is if there was one before thegit checkout. Is that what you're trying to detect?git write-tree. If you don't want to write a tree object, you can usegit ls-files --stageto check for any nonzero stage entries.test ! -z "$(git ls-files --unmerged --exclude-standard | head --bytes=1)"- I can't say for which criteria is is better or worse than the git-status variant, what I do see is that the listing is much more reduced for the check.git status --porcelain=v2, "Unmerged entries have the following format; the first character is a "u" to distinguish from ordinary changed entries."