Skip to content

azide0x37/git-clone-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

git-clone-rules

git-clone-rules is a small zsh wrapper for the one git clone case that should not require thought:

git clone git@github.com:someowner/somerepo.git

When the command is exactly git clone <github-url> and no destination path is provided, the wrapper maps the repository into:

~/Development/github.com/{owner}/{repo}

It prints the target path, asks for confirmation, creates the parent directory, and then hands the clone to the real git executable.

Why

Cloning a repository often includes a tiny but repeated context switch: checking the current directory, remembering where repositories belong, and avoiding accidental clones into unrelated worktrees or throwaway folders.

This tool encodes one filesystem rule once. GitHub repository provenance stays in the path, owner/name collisions stop being ambiguous, and everyday clones land in a predictable place.

The wrapper is intentionally narrow. It only intercepts the plain GitHub clone case. If you pass an explicit destination, use clone options, clone from another host, or run any non-clone Git command, normal Git behavior wins.

Supported URL Forms

git clone git@github.com:owner/repo.git
git clone https://github.com/owner/repo.git
git clone https://github.com/owner/repo
git clone ssh://git@github.com/owner/repo.git

Install

Make the script executable:

chmod +x bin/git-clone-rules

Then choose one deployment style.

Shell Function

This is the least invasive option. Add this to ~/.zshrc:

git() {
  /path/to/git-clone-rules/bin/git-clone-rules "$@"
}

Reload your shell:

source ~/.zshrc

PATH Shim

Create a directory that appears before the real Git executable on PATH, then symlink this script as git:

mkdir -p ~/.local/git-clone-rules/bin
ln -sf /path/to/git-clone-rules/bin/git-clone-rules ~/.local/git-clone-rules/bin/git

Add this before the system Git path in ~/.zshrc:

export PATH="$HOME/.local/git-clone-rules/bin:$PATH"

The wrapper searches PATH for the next git executable that is not itself. If your setup is unusual, pin the real binary explicitly:

export GIT_CLONE_RULES_REAL_GIT=/usr/bin/git

Configuration

Set a different clone root with:

export GIT_CLONE_RULES_BASE="$HOME/Code"

That changes the target layout to:

$GIT_CLONE_RULES_BASE/github.com/{owner}/{repo}

For non-interactive use, skip the prompt with:

GIT_CLONE_RULES_YES=1 git clone git@github.com:owner/repo.git

For a dry run:

GIT_CLONE_RULES_DRY_RUN=1 GIT_CLONE_RULES_YES=1 git clone git@github.com:owner/repo.git

Example

$ git clone git@github.com:someowner/somerepo.git

About to clone into:
  ~/Development/github.com/someowner/somerepo

Proceed? [y/N] y

Relationship To The Article

This repository packages the shell-wrapper idea from Teach git clone where repos belong: keep the boring clone path canonical, show the destination before doing work, and leave explicit overrides under the user's control.

Releases

No releases published

Packages

 
 
 

Contributors

Languages