Skip to content

Instantly share code, notes, and snippets.

@juandesant
Created March 18, 2022 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandesant/df06131666d80c34c6b9a7a9a7c1ea61 to your computer and use it in GitHub Desktop.
Save juandesant/df06131666d80c34c6b9a7a9a7c1ea61 to your computer and use it in GitHub Desktop.
Bash/ZSH function that returns the HTTP url for a Git repository
git-url () {
# Use `git config` to get the remote URL
git_url=$(git config --get remote.origin.url)
# Check if it is an HTTP-based URL
if [[ $git_url == *"http"* ]]
then
# for HTTP-based URLs, nothing to do but report it
echo $git_url
else
# for SSH based URLs, remake git_url so that the user is removed, and the server separator changed to a slash
git_url=$(echo "$git_url" | awk -F'@' '{print $2}' | sed 's/:/\//')
echo "https://$git_url"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment