A small CLI tool that clones Git repositories into a clean, consistent directory structure:
~/code/<host>/<org>/<repo>
No more mkdir -p before cloning. Just pass a URL in any format and the tool creates the right directories, clones the repo, and prints the resulting path.
git-clone <repository-url>The tool accepts any common Git URL format:
# HTTPS
git-clone https://github.com/org/repo.git
git-clone https://github.com/org/repo
# SSH
git-clone git@github.com:org/repo.git
# Bare (scheme is inferred)
git-clone github.com/org/repoOn success, the full path to the cloned repository is printed to stdout:
/home/user/code/github.com/org/repo
This makes it easy to combine with cd:
cd $(git-clone github.com/org/repo)| Variable | Default | Description |
|---|---|---|
GIT_CLONE_ROOT |
~/code |
Base directory for the organized tree |
go install github.com/ljagiello/git-clone@latestOr build from source:
git clone https://github.com/ljagiello/git-clone.git
cd git-clone
go build -o git-clone .- Parses the input URL (HTTPS, SSH
user@host:path,ssh://, or barehost/path). - Extracts
<host>/<org>/<repo>from the URL, normalizing the hostname to lowercase and stripping.gitsuffixes. - Joins the repo path with the base directory (
$GIT_CLONE_ROOTor~/code). - Creates parent directories and runs
git clone. - On failure, cleans up partial clones that are not recoverable and removes empty parent directories.