brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git ls-files --others --exclude-standard lists untracked files, one per line

Git
~/tips/tip-git-ls-files-others-exclude-standard

git ls-files --others --exclude-standard

Prints only the new files Git doesn't track yet, skipping everything in .gitignore, as plain paths.

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

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link