git status is nice to read and annoying to parse. When I want the list of new files in a script, I’d rather get bare paths without the ?? markers. There’s a plumbing command for that.
git ls-files --others --exclude-standard
--others shows files Git doesn’t track. On its own that includes everything you’ve ignored too, so --exclude-standard applies the usual rules: .gitignore, .git/info/exclude and your global ignore file.
I made a small repository with a .gitignore that lists *.log and build/, then added a notes.txt, a src/new.py, a debug.log and a build/o file. Without the flag I got all four paths. With it, this:
notes.txt
src/new.py
Paths are relative to the folder you run it in, one per line, which makes it easy to feed to other tools:
git ls-files --others --exclude-standard | xargs wc -l
A caveat: names with non-ASCII letters, tabs or newlines come out quoted and escaped (my é.txt showed up as "\303\251.txt). Add -z and pipe into xargs -0 when names can be odd. Also note that it only lists files that are untracked. A modified file that Git already tracks won’t show up here, so it’s not a replacement for git status, just the scriptable half of it.
Further reading: git-ls-files documentation