Undo Git mistakes

Delete untracked files in Git

Remove new files and folders Git isn't tracking, after checking the list first.

  1. List what would be deleted
    Terminal
    git clean -n -d

    Nothing is deleted yet. Check the list carefully.

  2. Delete the untracked files and folders
    Terminal
    git clean -f -d

    Deleted files do not go to the Bin. Files listed in .gitignore are left alone.

Check it worked

  1. Check the folder is clean
    Terminal
    git status

    It should say nothing to commit, working tree clean.

  1. List what would be deleted
    Terminal · Ubuntu / Debian
    git clean -n -d

    Nothing is deleted yet. Check the list carefully.

  2. Delete the untracked files and folders
    Terminal · Ubuntu / Debian
    git clean -f -d

    Deleted files do not go to the Bin. Files listed in .gitignore are left alone.

Check it worked

  1. Check the folder is clean
    Terminal · Ubuntu / Debian
    git status

    It should say nothing to commit, working tree clean.

  1. List what would be deleted
    PowerShell
    git clean -n -d

    Nothing is deleted yet. Check the list carefully.

  2. Delete the untracked files and folders
    PowerShell
    git clean -f -d

    Deleted files do not go to the Bin. Files listed in .gitignore are left alone.

Check it worked

  1. Check the folder is clean
    PowerShell
    git status

    It should say nothing to commit, working tree clean.