How to tell if a file is git tracked (by shell exit code)?

Issue

Is there a way to tell if a file is being tracked by running some git command and checking its exit code?

In other words: is git tracking a file?

Solution

try:

git ls-files --error-unmatch <file name>

will exit with 1 if file is not tracked

Answered By – hasen

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published