Skip to content

Instantly share code, notes, and snippets.

@bekicot
Last active November 18, 2018 04:34
Show Gist options
  • Save bekicot/548e50b29fb92d6ae8a2b5b8fe1cf792 to your computer and use it in GitHub Desktop.
Save bekicot/548e50b29fb92d6ae8a2b5b8fe1cf792 to your computer and use it in GitHub Desktop.
Clone GitHub Repo to nested directory with `username/repository_name`. Supports both ssh and https.
#!/usr/bin/env bash
# Usage Example
# github-clone git@github.com:rubygems/rubygems.org.git
# github-clone https://github.com/rubygems/rubygems.org.git
set -e
URI=$1
REPO=$(basename $1)
REPO="${REPO%.*}"
GITHUB_USERNAME=$(basename $(dirname $1))
GITHUB_USERNAME=${GITHUB_USERNAME##*:}
# e.g
# github-clone git@github.com:rubygems/rubygems.org.git
# Will clone the repository to rubygems/rubygems.
git clone $URI $GITHUB_USERNAME/$REPO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment