Languages
[Edit]
EN

Git - remove untracked files

6 points
Created by:
Marcin
2535

In this short article we would like to show how to remove untracked files using Git in command line.

Run following command:

git clean -fd

Where -fd means: clean files and directories.

Practical example

Let's suppose we want to remove logs directory.

Simple steps:

  1. check if some files are untracked
    git status

    Output:

    On branch master
    Your branch is up to date with 'origin/master'.
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
    	logs/
    
    nothing added to commit but untracked files present (use "git add" to track)
  2. clean untracked files
    git clean -fd

    Output:

    Removing logs/
  3. check if files were removed:
    git status

    Output:

    On branch master
    Your branch is up to date with 'origin/master'.
    
    nothing to commit, working tree clean
Hey 👋
Would you like to know what we do?
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.