Last active
February 5, 2019 20:49
-
-
Save swarupdonepudi/63f157675020f73cebd4972e839fcb54 to your computer and use it in GitHub Desktop.
git clone using browser url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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