Skip to content

Instantly share code, notes, and snippets.

@swarupdonepudi
Last active February 5, 2019 20:49
Show Gist options
  • Save swarupdonepudi/63f157675020f73cebd4972e839fcb54 to your computer and use it in GitHub Desktop.
Save swarupdonepudi/63f157675020f73cebd4972e839fcb54 to your computer and use it in GitHub Desktop.
git clone using browser url
#copy the below script to your local machine
#create an alias for this script and put it in your profile load file like ~/.zshrc or ~/.bashrc
function clone() {
echo ${1} > clone-url
hostname=$(perl -F'/' -lane 'print $F[2]' clone-url)
hn_github="github.com"
if [[ "$hostname" == ${hn_github} ]];
then
#browser url: https://github.com/swarupdonepudi/hypriot-k8s-userdata
#ssh url: git@github.com:swarupdonepudi/hypriot-k8s-userdata.git
username=$(perl -F'/' -lane 'print $F[3]' clone-url)
repo_name=$(perl -F'/' -lane 'print $F[4]' clone-url)
clone_url_ssh="git@github.com:${username}/${repo_name}.git"
else
echo "hostname: ${hostname}"
project_name=$(perl -F'/' -lane 'print $F[4]' clone-url)
repo_name=$(perl -F'/' -lane 'print $F[6]' clone-url)
clone_url_ssh="ssh://git@${hostname}/${project_name}/${repo_name}.git"
fi
echo "SSH Clone URL: ${clone_url_ssh}"
git clone ${clone_url_ssh}
rm -f clone-url
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment