Skip to content

Instantly share code, notes, and snippets.

@theptrk
Created February 27, 2024 23:47
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 theptrk/d99adbd97d9016dd2236b42597c1a253 to your computer and use it in GitHub Desktop.
Save theptrk/d99adbd97d9016dd2236b42597c1a253 to your computer and use it in GitHub Desktop.
function get_git_repo_url() {
# Get the SSH URL from the current Git configuration
local ssh_url=$(git config remote.origin.url)
# Check if ssh_url is empty
if [ -z "$ssh_url" ]; then
echo "Not a git repository or no origin set"
return 1
fi
# Convert SSH URL to HTTPS URL
local https_url=$(echo $ssh_url | sed -E 's|git@([^:]+):|https://\1/|')
# Optionally, handle the custom SSH alias (e.g., github.com-yourusername)
https_url=$(echo $https_url | sed -E 's|github.com-[^/]+/|github.com/|')
# Print the HTTPS URL
echo $https_url
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment