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?
I suggest a custom alias on you .gitconfig.
You have to way to do:
1) With git command:
git config --global alias.check-file
2) Editing ~/.gitconfig and add this line on alias section:
[alias]
check-file = "!f() { if [ $# -eq 0 ]; then echo 'Filename missing!'; else tracked=$(git ls-files ${1}); if [[ -z ${tracked} ]]; then echo 'File not tracked'; else echo 'File tracked'; fi; fi; }; f"
Once launched command (1) or saved file (2), on your workspace you can test it:
$ git check-file
$ Filename missing
$ git check-file README.md
$ File tracked
$ git check-file foo
$ File not tracked