Clone a git repository into ~/code/<owner>/<repo>, unless it's already there.
clone alpha-omega-security/scrutineer
clone https://github.com/alpha-omega-security/scrutineer/Both of these end up in ~/code/alpha-omega-security/scrutineer. If that directory already exists, nothing is cloned and the path is printed.
go install github.com/andrew/clone@latestMake sure $(go env GOPATH)/bin is on your PATH.
owner/repo(GitHub)github.com/owner/repohttps://github.com/owner/repo, with or without.git, a trailing slash, or deeper paths like/tree/main/cmdgit@github.com:owner/repo.gitandssh://git@github.com/owner/repo.git(cloned over SSH)- Full URLs for any other host, e.g.
git@codeberg.org:foo/bar.gitorhttps://gitlab.com/group/sub/repo
The host isn't part of the destination, so git@codeberg.org:foo/bar.git goes to ~/code/foo/bar. GitLab-style subgroups keep their full path (~/code/group/sub/repo).
If the destination already exists but none of its remotes point at the repo you asked for (say ~/code/foo/bar is a clone of github.com/foo/bar and you ask for codeberg.org/foo/bar), clone exits with an error. Pick a different location with --path, relative to ~/code unless absolute:
clone --path foo/bar-codeberg git@codeberg.org:foo/bar.gitThe destination path is printed to stdout, and git's output goes to stderr, so you can wrap it in a shell function to clone and cd in one step:
c() { local dir; dir="$(command clone "$@")" && cd "$dir"; }Set CLONE_ROOT to use a base directory other than ~/code:
CLONE_ROOT=~/src clone owner/repoMIT