git-force-clone
force-clone a repository, replacing the target directory if it exists
TLDR
SYNOPSIS
git force-clone [-b BRANCH] URL DIRECTORY
DESCRIPTION
git force-clone from the git-extras suite guarantees the target directory ends up as a fresh, clean clone of the given URL. It is the "just give me what's on the remote" hammer for deployment scripts:- If the directory does not exist, it clones normally.- If the directory is already a clone of the same URL, it fetches and hard-resets the working tree to match the remote, discarding any local changes.- If the directory exists but is a different repository (or contains unrelated files), it removes the directory and re-clones.
PARAMETERS
URL
Repository URL (https, ssh, git, or local path).DIRECTORY
Target directory. If it already exists and contains a clone of the same repo, its contents are reset to match the remote. If it exists but is a different repo (or random files), it is removed and re-cloned.-b BRANCH
Check out BRANCH after cloning.--help
Show help.
INSTALL
CAVEATS
Destructive. Uncommitted changes in the target directory are lost without confirmation. Local branches not pushed to the remote will be removed if the directory is re-cloned. Use with care, especially in interactive contexts — prefer `git fetch` + `git reset --hard` when you only need to resync and want to keep other local state.
HISTORY
git force-clone is part of git-extras, the long-running collection of git helpers by TJ Holowaychuk and contributors.
SEE ALSO
git-clone(1), git-reset(1), git-fetch(1), git-extras(1)