You are here: Home ยป Including untracked files in new directories in git status output

Including untracked files in new directories in git status output

Posted on Monday, May 26 2014 at 11:02 (Age: 5 yrs) | Category: Software Engineering

git status shows the status of the workspace - like which files have been modified or which files are new. For new directories with new files in them, the default behavior is to only show the directory name - but not the contents of the directory:

$ mkdir -p newDir/subDir
$ touch newDir/newFile1 newDir/newFile2 newDir/subDir/newFile3
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       newDir/
nothing added to commit but untracked files present (use "git add" to track)

I usually prefer to also see the contents of the directories - this can be achieved by adding the parameter --untracked-files=all to git status:

$ git status --untracked-files=all
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       newDir/newFile1
#       newDir/newFile2
#       newDir/subDir/newFile3
nothing added to commit but untracked files present (use "git add" to track)

It is a littlebit cumbersome to type this parameter each time, but Git allows to define aliases for commands. Straightforward, we can try to add the following alias to ~/.gitconfig:

[alias]
        status = status --untracked-files=all

Unfortunately, this will not work - Git does not allow to redefine existing commands (see "alias.*" at git-scm.com/docs/git-config). Some commands allow to add default parameters in ~/.gitconfig, in a format similar to

[status]
        untracked-files=all

but again, for status, this does not work.

The simplest way is to just define a new command alias, like

[alias]
        statusall = status --untracked-files=all

This will not change the default behaviour of the status command (which is probably good, since scripts might rely on the default output format of the command), but it simplifies the above command line:

$ git statusall
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       newDir/newFile1
#       newDir/newFile2
#       newDir/subDir/newFile3
nothing added to commit but untracked files present (use "git add" to track)

Comments

From: Emmly on Tuesday, July 12 2016 10:14:40

Created the greatest arilstec, you have.

From: Seston on Tuesday, July 12 2016 10:27:51

Notnhig I could say would give you undue credit for this story.

From: Kaden on Tuesday, July 12 2016 12:12:56

Phoenmenal breakdown of the topic, you should write for me too!