git-relink
Optimize Git object storage via hardlinks
SYNOPSIS
git-relink [-n] [-q] <git-repo> ...
PARAMETERS
-n
Dry-run mode; scan and report but do not modify files
-q
Quiet mode; suppress non-error output
DESCRIPTION
The git-relink command is a Perl script from Git's contrib directory designed to optimize disk space usage by replacing duplicate Git objects with hardlinks. It scans the object databases (.git/objects) of one or more Git repositories provided as arguments.
When identical objects (byte-for-byte matches) are found across repositories, git-relink replaces the copies in target repositories with hardlinks pointing to the source object's file. This is particularly useful for local development setups with multiple clones of the same repository, such as after using git clone --reference, or managing several worktrees.
It operates by computing checksums (SHA1) of objects and grouping identical ones, then relinking. All repositories must reside on the same filesystem for hardlinks to work. The script is non-interactive and modifies files in place, making it powerful but requiring caution.
Typical use case: Relink a fresh clone to an existing reference repo to drastically reduce storage needs without sacrificing independence.
CAVEATS
Requires all repositories on the same filesystem for hardlinks. Destructive operation—back up repositories first. Only relinks byte-identical objects. Not suitable for repositories with divergent histories. Not a core Git command; must be installed manually.
INSTALLATION
Download from Git source: git.git/contrib/relink/git-relink. Make executable with chmod +x git-relink and place in PATH.
EXAMPLE USAGE
git-relink ~/existing-repo ~/new-clone
Relinks objects from existing-repo into new-clone.
HISTORY
Developed by Petar Martic <petarm@gentoo.org> in 2007 as git/contrib/relink/git-relink. Included in Git source tree for optimizing local multi-repo setups. Remains in contrib due to niche use and risks.
SEE ALSO
git(1), git-clone(1), git-worktree(1)


