How to show only filenames with "git status"?

562 Views Asked by At

How do I show only filenames for all modified files in my repository? git status adds additional output, e.g.,

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
    modified:   my-file (modified content)

How do I get:

$ git status --name-only   # --name-only is not a valid option; what do I use instead?
my-file
2

There are 2 best solutions below

2
Rob Bednark On

Instead of git status, use git diff, e.g.,

$ # Show modified, unstaged files, and only the filenames
$ git diff --name-only --diff-filter=u
my-file

$ # Show modified, staged/cached files, and only the filenames
$ git diff --name-only --diff-filter=u --cached
my-staged-file
1
Romain Valeri On

There's an output option which does pretty much what you asked.

Only paths, with a letter to indicate A(dded), (M)odified, and so on.

git status -s [-b]