Skip to content

Instantly share code, notes, and snippets.

@viko16
Created February 5, 2026 16:26
Show Gist options
  • Select an option

  • Save viko16/2715a37e418d8fcf8654d55d74e6fc8e to your computer and use it in GitHub Desktop.

Select an option

Save viko16/2715a37e418d8fcf8654d55d74e6fc8e to your computer and use it in GitHub Desktop.
gitcd skill 版
name description compatibility allowed-tools
git-clone
Clones a git repository into a structured directory tree (Host/User/Repo) following git conventions. Handles URL parsing and idempotency (skips if exists) purely via instruction.
Requires 'git' installed in the environment.
Bash

Git Structured Clone

This skill enables you to clone git repositories into a canonical directory structure: ~/Code/<Host>/<User>/<Repo>.

Directory Structure Rules

You must enforce the following path construction logic based on the repository URL:

  1. Base Path: Defaults to ~/Code (unless user specifies otherwise).
  2. Host: The domain of the git provider (e.g., github.com, gitlab.com).
  3. User: The organization or username.
  4. Repo: The repository name (without .git suffix).

Logic Mapping Examples

Input URL Host User Repo Target Path
https://github.com/viko16/gitcd.plugin.zsh github.com viko16 gitcd.plugin.zsh ~/Code/github.com/viko16/gitcd.plugin.zsh
git@gitlab.com:my-org/backend.git gitlab.com my-org backend ~/Code/gitlab.com/my-org/backend
viko16/gitcd.plugin.zsh (Shorthand) github.com viko16 gitcd.plugin.zsh ~/Code/github.com/viko16/gitcd.plugin.zsh

Instructions

When the user asks to clone or download a repo:

  1. Parse the URL: Identify the Host, User, and Repo components based on the table above. If shorthand (user/repo) is provided, assume github.com and HTTPS.
  2. Construct the Command: Generate a single-line Bash command that performs an idempotent check before cloning.

Command Template

Do not run a simple git clone. You MUST use the following logic to prevent errors if the folder exists:

# Template (Replace placeholders)
TARGET_DIR="~/Code/<Host>/<User>/<Repo>"
if [ ! -d "$TARGET_DIR" ]; then
  echo "Cloning into structured path..."
  git clone "<URL>" "$TARGET_DIR"
else
  echo "Repository already exists at $TARGET_DIR"
fi
  1. Execute: Run the generated command using your Bash tool.
  2. Report: Inform the user of the absolute path where the code is located.

Example Execution

User: "Clone this repo https://github.com/viko16/gitcd.plugin.zsh"

Model Reasoning:

  • URL inferred: https://github.com/viko16/gitcd.plugin.zsh
  • Host: github.com, User: viko16, Repo: gitcd.plugin.zsh
  • Target: ~/Code/github.com/viko16/gitcd.plugin.zsh

Action (Bash):

target="~/Code/https://github.com/viko16/gitcd.plugin.zsh"
if [ ! -d "$target" ]; then
  git clone https://github.com/viko16/gitcd.plugin.zsh.git "$target"
else
  echo "Repo exists at $target"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment