Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
4  
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

3 Answers 3

up vote 21 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 at 22:20

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.