Data report"State of code review 2024" is now liveRead the full report

How to list all files in Git

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


To list all files currently being tracked by Git in your repository, you can use the git ls-files command. This command is particularly useful for seeing a complete list of files that Git is aware of in the staging area and working directory.

Command:

Terminal
git ls-files
Stop wrestling with Git commands

The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop Googling Git commands.

Learn more

If you want to list all files in a specific branch without switching to it, you can use the git ls-tree command along with the branch name. This command shows you all the files and directories in the tree structure of a branch.

Command:

Terminal
git ls-tree -r branch_name --name-only

Here, -r stands for recursive, so it lists all files in all directories, and --name-only simplifies the output to show just filenames.

To list all files as they were in a specific commit, you can use a similar approach to listing files in a branch, but instead, you use the commit hash.

Command:

Terminal
git ls-tree -r commit_hash --name-only

This will output all the files that were present in that particular commit.

If you want to see every file that has ever been part of the repository (including deleted and moved files), you'll need to use the git log command with some additional flags.

Command:

Terminal
git log --pretty=format: --name-only --diff-filter=A | sort -u

This command lists all files that have ever been added to the repository. The --diff-filter=A option filters for added files, while sort -u sorts the list and removes any duplicates.

You can also list all of the files that have been staged (added but not yet committed) by running:

Command:

Terminal
git diff --name-only --cached

This will show you all files that are currently staged, omitting all other files in the repo.

The best engineers use Graphite to simplify Git

Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.

Git started for free

Sometimes you might need more control or more specific information about the files in your repository.

You can use git log to list files based on specific criteria such as author, date, or type of change.

Example:

Terminal
git log --author="Author Name" --pretty=format: --name-only | sort -u

This command lists all files committed by a specific author.

You can also filter files based on the type of change (added, modified, deleted) across the history of the repository.

Command:

Terminal
git log --pretty=format: --name-status

This command shows all files along with their status (added, modified, deleted).

  • Regularly clean up local and remote branches to maintain a manageable list of files when checking different branches.
  • Use .gitignore effectively to keep unwanted files out of your tracked files list.

For more information on listing files in Git, see the official Git documentation.

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2