Search code examples
gitshellgithubversion-controlgit-remote

How to determine git remote name by giving the repo URL?


I'm trying to get the remote name of the giving URL:

$ git ls-remote --get-url

[email protected]:foo/bar.git
$ git remote -v

origin  [email protected]:my-username/bar.git (fetch)
origin  [email protected]:my-username/bar.git (push)
upstream    [email protected]:foo/bar.git (fetch)
upstream    [email protected]:foo/bar.git (push)

Is there any way to find the remote name by giving a URL [email protected]:foo/bar.git to determine which remote it belongs to?


Solution

  • I'm not aware of a way to do this directly with git, but you could pipe the result into a grep and format it:

    git remote -v | grep "[email protected]:foo/bar.git" | cut -f1 | head -1