This study will explain:
- How to List the Unstaged Files Using the “git clean -xn” command?
- How to List the Untracked Files Using the “git clean -dxn” command?
- How to Remove the Untracked Files Using the “git clean -fx” command?
How to List the Unstaged Files Using the “git clean -xn” command?
To list the untracked files using the “git clean” command along with the “-xn” option. To do so, we will first create a new file, place it in the working directory, and execute the previously discussed command along with the “-xn” option.
Step 1: Redirect to Local Repository
At first, utilize the provided command and switch to the target local repository:
Step 2: Create New File
Then, generate a new file by running the “touch” command:
Step 3: Track Modifications
Now, execute the following command to track the added changes:
Step 4: Generate New File
Similarly, make a new file with the help of the provided command:
Step 5: Check Git Status
Next, run the “git status .” command to show the current working repository status:
According to the below-given output, the most recently created “file3.txt” file is placed in the working directory:
Step 6: View Untracked File
To list the untracked files, run the “git clean” command:
Here, the “-xn” option is used for displaying the list of all untracked and ignored files of the repository that need to be deleted:
How to List the Untracked Files Using the “git clean -dxn” command?
Another way to check the list of all unstaged files is by executing the following command:
How to Remove the Untracked Files Using the “git clean -fx” command?
Suppose developers want to delete all untracked files from the Git working area. In that case, the “git clean” command can be used along with the “-xf” option:
According to the provided output, the untracked file is removed successfully:
That’s it! We have explained the usage of the “git clean” command along with the “-x” option for listing and removing untracked files.
Conclusion
The “git clean” command is used for deleting the unstaged files. It can display the list of untracked files along with the “-x” option. If developers want to list the untracked files, the “git clean -xn” and “git clean -dxn” commands can be used. To remove the untracked files the “git clean -xf” command can be used to remove the untracked files. This study illustrated the usage of the “git clean” command along with the “-x” option.