221k views
4 votes
How to discard untracked files in git

User Nori
by
8.1k points

1 Answer

4 votes

Final answer:

To discard untracked files in Git, use 'git clean -f'. For a dry run to see what would be deleted without actually doing it, use 'git clean -n'. Take caution as this command permanently deletes the files.

Step-by-step explanation:

To discard untracked files in git, you would want to use the clean command. This command removes untracked files from your working directory. It is critical to use this command with care, as it will permanently delete these files, and they cannot be recovered afterwards. Here's the command to use:

git clean -f

This will remove all untracked files. If you also have untracked directories, you can use the following command to remove both untracked files and directories:

git clean -fd

As a safety measure, you might want to use the -n option for a dry run to see what will be deleted:

git clean -n

This will show you a list of files that would be deleted without actually deleting them.

User Luis Sep
by
8.3k points