QA
Beginner LevelGit & GitHub

How do you remove untracked files and directories using git clean?

❓ Interview Prompt: Explain git clean, dry-run safety (-n), recursive directory cleaning (-d), force flags (-f), and ignoring .gitignore rules (-x).

git clean removes untracked files and directories from your working directory. git clean -n runs dry-run mode (always run -n first!). git clean -fd deletes untracked files and directories. git clean -fdx deletes ignored build artifacts too.

Code Implementation Example

bash
git clean -nd
git clean -fd
git clean -fdx
💡Previewing and cleaning untracked files using git clean.
🎯 Interview Key Takeaway

Always run git clean -n first to preview files before running git clean -fd to delete untracked files safely.

#git clean#Untracked Files#Beginner
Back to all Git & GitHub Questions→

More Git & GitHub Interview Questions

Beginner LevelGit & GitHub

Compare git rebase versus git merge and explain how git bisect finds regressions.

Beginner LevelGit & GitHub

What is the difference between git init and git clone?

Beginner LevelGit & GitHub

What are the Three Trees in Git (Working Directory, Staging Area / Index, Commit History)?