Show untracked files with git status

17 May 2021 in TIL

Customise how `git` shows untracked folders and files in your repository using the `-u` flag, or the `showUntrackedFiles` config option

When working with new folders, git does not show the contents of those folders by default when you run git status.

Here's an example of what it shows whilst writing this post:

git status
On branch git-status-untracked
Untracked files:
(use "git add <file>..." to include in what will be committed)
_posts/git-status-untracked/

nothing added to commit but untracked files present (use "git add" to track)

Usually I want to see what files are in there rather than adding the whole folder with git add _posts/git-status-untracked. I've always changed directory into the folder to check, but today I learned about the -u flag to git status. Adding -u shows untracked files:

git status -u
On branch git-status-untracked
Untracked files:
(use "git add <file>..." to include in what will be committed)
_posts/git-status-untracked/index.md

nothing added to commit but untracked files present (use "git add" to track)

There are three parameters available for -u:

  • -uno which doesn't show any untracked files. This is useful when you only want to see the status of files already added to the index
  • -unormal which shows untracked files and directories. This is the default behaviour of git status
  • -uall Which shows individual files in untracked directories. This is the same as passing -u

If you want to enable -uall permanently, you can set it in your git config:

git config --global status.showUntrackedFiles all

If you enable this globally, be aware of this warning from the man page for git:

it takes extra work to find untracked files in the filesystem, this mode may take some time in a large working tree.