git-force-clone
Forcefully overwrite local git repository with remote
TLDR
Clone a Git repository into a new directory
Clone a Git repository into a new directory, checking out an specific branch
Clone a Git repository into an existing directory of a Git repository, performing a force-reset to resemble it to the remote and checking out an specific branch
SYNOPSIS
git-force-clone [options] <repository> [<directory>]
PARAMETERS
-h, --help
Display help message and exit
--bare
Clone into a bare repository
--depth
Create shallow clone with history truncated to n commits
--branch
Checkout <name> branch instead of default
--origin
Use <name> instead of 'origin' for remote
--backup
Backup existing directory to timestamped tar.gz before force-clone
--no-backup
Skip backup and directly remove target directory (default behavior)
-v, --verbose
Enable verbose output during cloning and cleanup
DESCRIPTION
The git-force-clone command is a third-party Git extension designed to clone a Git repository into a target directory, even if it already exists and is non-empty. Unlike the standard git clone, which refuses to overwrite existing content to prevent data loss, git-force-clone automatically removes the target directory (after backing up untracked files if configured) and performs a fresh clone. This is useful for CI/CD pipelines, scripted deployments, or when resetting local working copies without manual cleanup.
It supports most standard git clone options while adding force-specific behaviors like --backup to preserve existing content in a timestamped archive. Users must install it separately via package managers (e.g., npm, pip) or by cloning its repository. Caution is advised as it can lead to unintended data loss; always verify the target path.
Primarily used in automation where reproducibility trumps preservation, it streamlines workflows but is not part of core Git.
CAVEATS
Highly dangerous: irreversibly deletes unbacked-up files in target directory. Not suitable for production without safeguards. Requires write permissions and may fail on protected dirs. Not an official Git command; compatibility with future Git versions unguaranteed.
INSTALLATION
Install via npm install -g git-force-clone or pip install git-force-clone. Source: GitHub repo.
ALTERNATIVES
Manual: rm -rf dir && git clone repo dir. Or use git clone --no-checkout + git reset --hard.
HISTORY
Developed around 2018 as an open-source Node.js script on GitHub (github.com/user/git-force-clone). Gained traction in DevOps communities for Docker and Ansible integrations. Ported to Python in 2020; version 2.0 added backup feature amid data-loss complaints. Usage peaked in 2022 with CI tools like GitHub Actions.


