Search code examples
gitversion-control

How to run "git status" and just get the filenames


How can I run "git status" and just get the filenames as opposed to the long relative path?


Solution

  • The output of git status --porcelain, designed to be easy to parse in a script, outputs the full paths rather than relative paths regardless of where your current directory is within the tree.

    Each line output by git status --porcelain has two leading characters indicating the status of the file (e.g. whether it's untracked, modified, new, deleted, etc.) followed by a space, so if you just want the full paths of everything that would be mentioned in the output of git status you can do:

    git status --porcelain | sed s/^...//