Skip to content

nkaewam/git-clonepath

Repository files navigation

git-clonepath

git-clonepath is a Git external subcommand that derives every clone destination from the remote:

<clonepath.root>/<host>/<repository-path>

For example:

git config --global clonepath.root ~/Developer
git clonepath git@github.com:nkaewam/git-clonepath.git

clones into:

~/Developer/github.com/nkaewam/git-clonepath

Installation

Git must already be installed. Prebuilt git-clonepath binaries are available for macOS and Linux on AMD64 and ARM64.

Homebrew (recommended)

Install the appropriate prebuilt release binary from the nkaewam/tap tap:

brew install nkaewam/tap/git-clonepath

Go is not required. To upgrade later:

brew update
brew upgrade git-clonepath

Verify that the executable is available:

command -v git-clonepath

GitHub Releases

Without Homebrew, download and verify the archive for the current operating system and CPU architecture from GitHub Releases. Set VERSION to the release tag to install:

VERSION=v0.1.1

case "$(uname -s)" in
  Darwin) OS=darwin ;;
  Linux) OS=linux ;;
  *) echo "Unsupported operating system: $(uname -s)" >&2; exit 1 ;;
esac

case "$(uname -m)" in
  x86_64|amd64) ARCH=amd64 ;;
  arm64|aarch64) ARCH=arm64 ;;
  *) echo "Unsupported CPU architecture: $(uname -m)" >&2; exit 1 ;;
esac

PACKAGE="git-clonepath_${VERSION#v}_${OS}_${ARCH}"
ARCHIVE="${PACKAGE}.tar.gz"
BASE_URL="https://github.com/nkaewam/git-clonepath/releases/download/${VERSION}"

curl -fLO "${BASE_URL}/${ARCHIVE}"
curl -fLO "${BASE_URL}/SHA256SUMS"

if [ "${OS}" = darwin ]; then
  grep " ${ARCHIVE}$" SHA256SUMS | shasum -a 256 -c -
else
  grep " ${ARCHIVE}$" SHA256SUMS | sha256sum -c -
fi

tar -xzf "${ARCHIVE}"
mkdir -p "${HOME}/.local/bin"
install -m 0755 "${PACKAGE}/git-clonepath" "${HOME}/.local/bin/git-clonepath"

Ensure ~/.local/bin is on PATH, adding the export to your shell profile if needed:

export PATH="${HOME}/.local/bin:${PATH}"
command -v git-clonepath

Build from source

With Go installed, build and install the latest tagged version:

go install github.com/nkaewam/clone-path/cmd/git-clonepath@latest

Ensure the Go binary directory is on PATH, then verify the installation:

command -v git-clonepath

Git automatically exposes an executable named git-clonepath as git clonepath.

Configure

The clone root is required. It must resolve to an absolute, existing directory:

mkdir -p ~/Developer
git config --global clonepath.root ~/Developer

Normal Git configuration precedence applies, including one-off overrides:

git -c clonepath.root=~/Work clonepath https://github.com/acme/widgets.git

Use

SCP-style SSH, ssh://, and https:// remotes are supported:

git clonepath git@github.com:acme/widgets.git
git clonepath ssh://git@github.com:2222/acme/widgets.git
git clonepath https://github.com/acme/widgets.git

Clone options before the remote are forwarded unchanged:

git clonepath --depth 1 --branch main https://github.com/acme/widgets.git

After a successful clone, the command logs a shell-safe command that can be copied to enter the new repository:

git-clonepath: next command:
  cd /Users/alice/Developer/github.com/acme/widgets

The original remote is passed to Git unchanged. Usernames and ports are omitted only when deriving the local path. Local and file:// remotes are rejected, as are unsafe or malformed repository paths.

An existing destination is always an error. On a failed clone, the command removes only the empty host and namespace directories it created. Git's standard input, output, error, credential handling, and exact clone exit status are preserved.

Develop

task test
task integration

Build the supported release targets:

task release

Release

Release Please monitors commits pushed to main and maintains a release pull request. Use Conventional Commits: fix: makes a patch release, feat: makes a minor release, and ! denotes a breaking change and makes a major release. Merging the release pull request creates the version tag automatically.

The release workflow tests the project, builds all four targets, generates SHA256SUMS, creates a GitHub Release with generated release notes, and updates the formula in nkaewam/homebrew-tap.

For the Homebrew update, add a HOMEBREW_TAP_TOKEN Actions repository secret. Use a fine-grained personal access token with read/write access to repository contents for only nkaewam/homebrew-tap.

To retry only the Homebrew update for an existing release, run the Release workflow manually, enter its tag, and select Update the Homebrew formula without rebuilding or republishing the release.

About

Git external subcommand that derives every clone destination from the remote

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages