WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Intermediate · question 39 of 100

How do you use ’git clean’ to remove untracked files and directories?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

The git clean command is used to remove untracked files and directories from the working directory. By default, git clean will only remove files that are not being tracked by Git, but you can also use options to remove directories or force the removal of files that are ignored by Git.

Here’s how to use git clean to remove untracked files and directories:

View the untracked files and directories using the git status command.

    git status

This will show you the files and directories that are not being tracked by Git.

Dry-run git clean to see which files and directories would be removed.

    git clean -n

This will perform a dry-run of git clean, which means that it will show you which files and directories would be removed, but it won’t actually remove them.

Remove untracked files and directories.

    git clean -f

This will remove the untracked files and directories from the working directory.

You can use additional options with git clean to modify its behavior:

-d: Remove untracked directories in addition to files. -x: Remove untracked files and directories that are ignored by Git. -n: Perform a dry-run of git clean to see which files and directories would be removed. -f: Force the removal of files and directories, even if they are not writable or have merge conflicts.

In summary, git clean is used to remove untracked files and directories from the working directory. You can use additional options to remove directories, force the removal of ignored files, perform a dry-run, or force the removal of files and directories that have conflicts. Be careful when using git clean, as it can permanently delete files that you may not intend to remove. It’s a good idea to perform a dry-run first to make sure that you know which files and directories will be removed.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics