git clean
git clean
: Clean the working directory by removing untracked files.
In Git, the git clean
command is used to clean up your working directory by removing files that are not tracked by Git. Untracked files are those that haven't been added to the version control's tracking system, typically because they are temporary or generated files that don't need to be included in the project history. Think of files like compiled binaries, temporary logs, or project files that clutter your workspace but aren't necessary for version control.
Using git clean
rather than manually deleting files helps ensure you only remove untracked files, so you don't accidentally delete tracked files that are important to your project. This command can be useful when you want to reset your directory to a clean state before starting fresh with new changes.
However, be cautious with git clean
because it permanently deletes files. Once removed, they cannot be recovered from Git or your system's trash or recycle bin.
Examples
Run a clean up in interactive mode, which allows you to review each file before removing it:
git clean -i
The above command will ignore directories. To include directories, use the -d
flag:
git clean -id
If you are sure of what you're doing, forcefully delete all untracked files:
git clean -f
To include directories as well:
git clean -fd
Simulate a clean up, showing what files would be removed without actually deleting them:
git clean -n
To include directories in the simulation:
git clean -nd
Hi! I'm Alex, creator of GitByBit.
And this is Gitopedia—a reference that summarizes knowledge in my Git course.
Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:
Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.