Take the 2-minute tour ×

I coding a PHP script that has to check if exists a GitHub repo that the user enters. But I don't know how can I do it. I think the main matter is to know which HTTP code gives GitHub, but I can't find anything like that in cURL PHP documentation. How can I do it? Thanks.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

HTTP in istelf is a rather simple protocol, so just check if you get a 404. That'd mean it doesn't exist. As an alternative to cURL, you might want to consider using get_headers, that's less intensive to write.

share|improve this answer
Assuming you're looking for a public repo. If you're checking a private repo and don't provide auth for a user that has access to it, you'll get a 404. –  Tekkub Jun 4 '11 at 21:54
@Tekkub Fair enough. If you want to do that, the Github API would be your better chance. –  Berry Langerak Jun 6 '11 at 7:41
You can provide a token as password to allow cURL to authenticate if you have two-factor-authentication turned on. –  Henry Blyth Jan 20 at 19:27

Check out the GitHub API, that might be the best way to proceed.

share|improve this answer
I've already checked, but there's no way of doing that through the API. –  Carlos Precioso Jun 4 '11 at 15:51
Of course there is, but you have to use the old version: Repositories API. –  svick Jun 4 '11 at 16:03
Thanks, upvote for that, I didn't noticed, but I'll use Berry's answer. –  Carlos Precioso Jun 4 '11 at 16:05

If the repository is private or does not exist, you should get a 404 http status header. Check against the headers that are returned by a cURL request for the HTTP status header.

share|improve this answer
But, the question was, how do I check the headers? –  Carlos Precioso Jun 4 '11 at 15:52
stackoverflow.com/questions/408405/… this looks relevant - check the #1 answer –  damianb Jun 4 '11 at 15:57
Thanks @Obsidian_ , but #1 answer (of this question) already gave me a better way of doing it. –  Carlos Precioso Jun 4 '11 at 16:01
no prob -- I was assuming you were using cURL already for a reason. P: –  damianb Jun 4 '11 at 16:01
Yeah, but I was only using it for this check, so I don't mind the change. –  Carlos Precioso Jun 4 '11 at 16:03

Your Answer


