List files in local Git repo?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
If you want to list files in a local Git repository, the correct command depends on what you mean by "files". Git can show tracked files, untracked files, ignored files, or the contents of a specific commit. The most useful everyday command is git ls-files, but it is only one part of the picture.
List Tracked Files
To list files that Git currently tracks in the working tree, use:
This prints paths known to the index, which is usually what people want when they ask for repository files. It is fast and script-friendly because it outputs only file paths.
You can also filter by path prefix:
That is useful in larger repositories when you want only one directory subtree.
List Untracked Files
Tracked files are not the whole story. If you want files Git sees locally but has not started tracking, use:
--exclude-standard matters because it applies normal ignore rules from .gitignore, global ignores, and .git/info/exclude. Without it, the output is often much noisier than expected.
List Ignored Files
Sometimes the question is really "what files exist here but Git is ignoring". That command is:
This is handy when debugging why a file is not showing up in git status.
List Files From a Specific Commit
If you want the files stored in HEAD or another commit, use git ls-tree:
That is different from git ls-files:
- '
git ls-filesfocuses on the index and working tree view' - '
git ls-treeshows the tree object stored in a commit'
This distinction matters when the working tree contains staged or deleted changes that do not match the last commit.
Compare With git status
git status --short is often a better human-facing overview than git ls-files, because it includes change state along with file paths.
Use git status when you want a work summary. Use git ls-files when you want precise file lists for scripting or inspection.
Practical Examples
List tracked files that match a pattern:
List deleted tracked files:
List modified tracked files relative to the index:
These switches are useful in automation, but they are also great for debugging strange repository state locally.
When the Command Appears to "Miss" Files
If a file is present on disk but missing from git ls-files, ask:
- Is it untracked
- Is it ignored
- Am I looking for working-tree files or committed files
Those three questions usually explain the difference immediately.
Another common issue is running the command outside the repository root or inside the wrong repository when several nested projects exist on a machine.
Common Pitfalls
- Using
git ls-filesand expecting untracked files to appear. - Forgetting
--exclude-standardwhen listing untracked or ignored files. - Confusing committed-tree listing with working-tree listing.
- Using
git statusoutput in scripts whengit ls-fileswould be cleaner. - Running file-list commands from the wrong repository or submodule.
Summary
- Use
git ls-filesto list tracked files in the local repository. - Use
git ls-files --others --exclude-standardfor untracked files. - Use
git ls-tree -r --name-only HEADfor files stored in a specific commit. - Pick the command based on whether you care about tracked, untracked, ignored, or committed files.
- When results look wrong, first check whether the file is ignored or simply untracked.
Related reading
- List increment for redis
- list_local_device tensorflow does not detect gpu
- List of all classification algorithms
- List of lists changes reflected across sublists unexpectedly
- List files modified for particular git commit
- List Git aliases
- List of lists changes reflected across sublists unexpectedly
- List of lists into numpy array

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.