git "ping": check if remote repository exists

I'd like to know whether a remote repository exists. Here's what I came up with:

git ls-remote -h "$REPO_URL" &> /dev/null

Is there any better way?


Solution 1:

I think the git ls-remote command is pretty much made for that purpose.

Solution 2:

If you use --exit-code argument you can skip sending output to null. It will return something only in case of error.

Also, you can use -h argument to show only heads references.

git ls-remote --exit-code -h "$REPO_URL"

Solution 3:

You can narrow output by using something like git ls-remote "$REPO_URL" HEAD