Get a list of each file in a Git repository via the command line?

Answered
looper003 asked this question 6 months ago
looper003 on Mar 16

How can I get a list of all the files in my Git repository on my local machine? Is there a way to do this via the command line?

If it matters, my machine is a Macbook Pro.

Thanks in advance!

4 suggested answers
nick on Mar 16 · Edited

Try this Git command:

git ls-files

That will give you full list of each file in your Git repository, including ones that are currently staged.

Git documentation: https://git-scm.com/docs/git-ls-files.

0 replies
rusty1_rusty1 on Mar 16 · Edited
git ls-tree --full-tree -r --name-only HEAD

This will list all the files that have been committed to the repo.

  • --full-tree: tells Git to include the entire directory. As if the command was ran from your project root.
  • -r: tells Git to recursively go through each directory in the repo.
  • --name-only: tells Git to only include the file paths.
  • HEAD: then name of the branch you want information for. This can be changed to master, develop, etc.
0 replies
moon_man41 on Mar 16

List the files for a specific branch:

git ls-tree -r master --name-only

Replace master with the name of the branch you want to examine.

0 replies
coderguy on Mar 16

This will list all the files that have existed in your repo:

git log --pretty=format: --name-status | cut -f2- | sort -u
0 replies
Answered