Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

Is there any better way?

share|improve this question
It seems like a fine choice. The overhead of the “extra work” of fetching and formatting the list of refs (which is then sent to /dev/null) should be fairly small. – Chris Johnsen Dec 31 '10 at 0:57
up vote 33 down vote accepted

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

share|improve this answer
Thanks Chris, thanks Peter! – Jo Liss Jan 2 '11 at 17:43

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"
share|improve this answer
-h is a great idea. However, --exit-code is not the right choice here. The man page says: Exit with status "2" when no matching refs are found in the remote repository. This means that git ls-remote --exit-code "$REPO_URL" will fail for an empty repo that has only just been initialized with git init. – Jo Liss May 16 '15 at 22:20

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .