Using command line git, how can I make git show a list of the files that are being tracked in the repository?
601
votes
possible duplicate of List files in local git repo?
– Kristján
I believe it is. But it does not feel right to mark this as dup when this has a better answer.
– lindhe
in a parallel universe, it's uncanny how similar this question is including all the answers, yet each with its own distinctive flair.
– Jeff Puckett
4 Answers
722
votes
25
votes
The accepted answer only shows files in the current directory's tree. To show all of the tracked files that have been committed (on the current branch), use
git ls-tree --full-tree --name-only -r HEAD
--full-tree
makes the command run as if you were in the repo's root directory.-r
recurses into subdirectories. Combined with--full-tree
, this gives you all committed, tracked files.--name-only
removes SHA / permission info for when you just want the file paths.HEAD
specifies which branch you want the list of tracked, committed files for. You could change this tomaster
or any other branch name, butHEAD
is the commit you have checked out right now.
This is the method from the accepted answer to the ~duplicate question https://stackoverflow.com/a/8533413/4880003.
6
votes
You might want colored output with this.
I use this one-liner for listing the tracked files and directories in the current directory of the current branch:
ls --group-directories-first --color=auto -d $(git ls-tree $(git branch | grep \* | cut -d " " -f2) --name-only)
You might want to add it as an alias:
alias gl='ls --group-directories-first --color=auto -d $(git ls-tree $(git branch | grep \* | cut -d " " -f2) --name-only)'
If you want to recursively list files:
'ls' --color=auto -d $(git ls-tree -rt $(git branch | grep \* | cut -d " " -f2) --name-only)
And an alias:
alias glr="'ls' --color=auto -d \$(git ls-tree -rt \$(git branch | grep \\* | cut -d \" \" -f2) --name-only)"