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
SYNOPSIS
git-clear [options] [-- paths...]
PARAMETERS
-f, --force
If implemented, typically forces the removal of files without confirmation. Essential for actual deletion when the command is run.
-n, --dry-run
If implemented, performs a trial run, showing which files and directories would be removed without actually deleting them. Useful for previewing changes.
-x
If implemented, includes files and directories specified by .gitignore in the cleanup process, in addition to untracked files.
-d
If implemented, also removes untracked directories, in addition to untracked files.
--all
A hypothetical option for a more aggressive cleanup, potentially combining actions like git clean, git gc, and even resetting local changes to a pristine state.
--local
A hypothetical option to specifically target and clear only local, uncommitted changes, potentially by resetting the working directory and index.
--
If supported, limits the cleanup operation to specific paths or directories within the repository. Anything outside these paths would be unaffected.
DESCRIPTION
git-clear is not a standard command distributed with Git. It typically refers to a user-defined alias or a custom script designed to provide a more comprehensive or simplified way to clean up a Git repository's working directory. While the exact behavior depends entirely on its implementation, it commonly aims to remove untracked files, ignored files (if explicitly requested), and potentially prune empty directories or clean up Git's internal garbage. It often serves as a convenience wrapper around standard Git commands like git clean, git reset, or git gc, combining their functionalities for a quicker cleanup workflow. Users often create such scripts to automate repetitive cleanup tasks, such as preparing a repository for a fresh build or ensuring a pristine working state. Due to its custom nature, its functionality can vary widely, from a simple wrapper for git clean -fdx to a more aggressive script that might also prune branches or revert local changes. Always exercise caution when using non-standard cleanup scripts, as they can lead to unintended data loss if not properly understood.
CAVEATS
Important: git-clear is not a standard Git command. Its functionality is entirely dependent on how it's implemented (as an alias or a custom script) by an individual user or team. Using it without understanding its source code can lead to irreversible data loss. Always inspect the underlying script or alias definition before execution, especially in production environments or with critical data. Its behavior can differ significantly from similar standard Git commands like git clean.
HOW TO IMPLEMENT (HYPOTHETICAL EXAMPLE)
A common way to define a git-clear command is through a Git alias or a shell script. For instance, you could add git config --global alias.clear 'clean -fdx'
to make git clear
an alias for git clean -fdx
. Alternatively, a more complex script might look like:#!/bin/bash
git clean -fdx
git gc --prune=now
echo 'Repository cleared!'
The actual implementation determines its behavior.
SAFETY BEST PRACTICES
Before running any custom cleanup script or alias, especially one named git-clear, it is highly recommended to:
1. Inspect its source code: Understand exactly what commands it executes.
2. Use dry-run first: If supported (e.g., git clean -n), always preview changes.
3. Commit or stash important work: Ensure no valuable uncommitted changes are present.
4. Back up: For critical repositories, consider a full backup.
HISTORY
As git-clear is not a part of the official Git distribution, it does not have a formal development history. Instead, it represents a common pattern among Git users to create custom aliases or scripts to streamline their workflows. Users often develop such commands to bundle frequently used cleanup operations (e.g., combining git clean with git gc or a hard reset) into a single, memorable command. This trend highlights the extensibility of Git and the community's desire for personalized, efficient tooling.
SEE ALSO
git-clean(1), git-reset(1), git-gc(1), git-status(1), git-restore(1)