Skip to content

Instantly share code, notes, and snippets.

@shitchell
Last active July 7, 2020 01:00
Show Gist options
  • Save shitchell/c7c42d684110ca477a8534cab0cf30c6 to your computer and use it in GitHub Desktop.
Save shitchell/c7c42d684110ca477a8534cab0cf30c6 to your computer and use it in GitHub Desktop.
Clone a github repository with just the username and repository name: github-clone shitchell qrng
#!/bin/bash
usage() {
echo "usage: $(basename $0) github-user github-repository"
echo " $(basename $0) github-user/github-repository"
}
if [[ "$#" -ne 1 && "$#" -ne 2 ]]; then # require exactly 1 or 2 arguments
usage && exit
elif [[ "$#" -eq 1 && "$1" != *"/"* ]]; then # if one argument provided, require a slash
usage && exit
elif [[ -n "$2" ]]; then # set the url based on 2 arguments
URL=git@github.com:$1/$2.git
else # set the url based on one argument
URL=git@github.com:$1.git
fi
echo $URL
git clone $URL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment