During the development procedure, the programmers and other Git users often create multiple files with different extensions. After generating files, they realize some files are unwanted, and they don’t want to push them to the Git repository. For this purpose, first, they need to list all unstaged files with the help of the Git commands.
This post provides the procedure for viewing all existing untracked files.
How to List Only “Untracked” Files Including the Custom Commands?
The “git status .” command can be used to list the all unstaged files of the repository. To do so, execute the following steps.
Step 1: Redirect to Git Required Repository
First, use the “cd” command along with the desired repository path and switch to it:
Step 2: Generate New File
Next, generate a new text file by executing the below-stated command:
Step 3: View Repositories’ Current Status
Then, view the repository’s existing all untracked files by checking their status with the help of the “git status” command:
As you can see, the current working repository contains the “file2.py” untracked file:
How to List “Untracked” Files Using “git clean” Command?
The “git clean” command along with the “-xdn” option basically, used for listing the untracked files, folders, and ignored files. For instance:
In the above-listed command, the:
-
- “x” is used to show all existing untracked files, including ignored ones.
- “d” displays the unstaged folders/directories.
- “n” is individually used for a clean mechanism to show the results.
It can be seen in the below output, the current working repository contains the “file2.py” unstaged file:
How to List “Untracked” Files Using Custom Command?
Another way to list the untracked files is by using the following custom command:
Here:
-
- “ls-files” will be used to show the list of files.
- “–other” option is used for listing untracked files.
- “–exclude-standard” pattern is utilized for finding the particular files/folders when the “–other” flag is used.
It can be seen that the “file2.py” is the untracked file that exists in the repository:
We have provided the easiest ways of listing the untracked files from the repository.
Conclusion
To list all untracked files, the “git status .” and “git clean -xdn” Git commands are used. Another way to list the unstaged files is using the custom command, that is, the “git ls-files –others –exclude-standard” command. This post demonstrated the method of viewing all existing untracked files.