Created
March 18, 2022 15:33
-
-
Save juandesant/df06131666d80c34c6b9a7a9a7c1ea61 to your computer and use it in GitHub Desktop.
Bash/ZSH function that returns the HTTP url for a Git repository
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
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