Recover the remote URL from a Git repository

When you download a Git repository, many times you’re interested in going to the GitHub (or GitLab, or BitBucket… you get the idea) repository. Maybe you want to use Merge Requests, or comments, or raise an issue…

You can get the URL with the git command

git config --get remote.origin.url

This URL can be directly used in a macOS open command like this:

open $(git config --get remote.origin.url)

But that is only true if the reported URL is an HTTP-based one, and sometimes repositories have been downloaed using SSH. Also, the git config syntax is difficult to remember, so I created a helper bash/zsh function git-url which is availble as a GitHub Gist:

Hope that is useful for you… I know I find it useful for me!