LinuxCommandLibrary

git-clear

Remove untracked and ignored Git files

TLDR

Reset all tracked files and delete all untracked files even if they are included in the .gitignore

$ git clear
copy

SYNOPSIS

git-clear [options]

PARAMETERS

--dry-run
    Preview files/folders to be deleted without removing them

--help
    Display usage information

--version
    Output version number

DESCRIPTION

git-clear is a third-party command-line tool designed to completely wipe the working directory of a Git repository, deleting all files and folders except the .git directory. This effectively resets the repository to a clean state containing only the commit history, allowing developers to start fresh without the baggage of untracked or modified files.

Unlike git clean, which targets only untracked files, git-clear is far more aggressive—it removes everything outside .git, including tracked files that haven't been committed. It's useful for scenarios like cleaning up after experiments, preparing a repo for a complete rewrite, or salvaging a repo after a messy development session.

Installation requires Node.js and npm: run npm install --global git-clear. Once installed, navigate to your Git repo and execute git-clear. Always use --dry-run first to preview changes.

This tool is not part of core Git; it's maintained by Sindre Sorhus and available via npm.

CAVEATS

Extremely destructive—permanently deletes all files except .git. No undo possible. Test with --dry-run. Not suitable for repos with uncommitted work.

INSTALLATION

npm install --global git-clear
Requires Node.js ≥ 12.

EXAMPLE USAGE

cd my-repo
git-clear --dry-run # Preview
git-clear # Execute

HISTORY

Created by Sindre Sorhus in 2015 as an npm package. Remains actively maintained with updates for Node.js compatibility. Popular for its simplicity in repo cleanup tasks.

SEE ALSO

git clean(1), git reset(1), rm(1)

Copied to clipboard