Check if public GitHub repository exists without using api, using bash?



After having applied this solution, I noticed I got rate limiting after calling the function 5 times in a span of +-3 minutes. I expect this may have been because someone in the location/ip in which I was testing the function, was already consuming some of the API bandwith. So I added a personal access token to the API call to overcome the API rate limiting.

However, this check is used in an installation script in that does not have access to a GitHub personal access token. Hence, I would like to use a more robust check on whether a GitHub repository exists. I think this is possible, because regardless of the API rate-limiting, I am able to go to the website ( and see whether the repository exists.


Hence, I would like to ask, how can one check if a public GitHub repository exists, without using the GitHub API, in bash?

>Solution :

Just try to fetch the main repository page using curl with the --fail option (which causes curl to return an error code in response to HTTP errors):

if curl --silent --fail; then
  echo repository exists
  echo repository does not exist

As pointed out in comments, this will only work for public repositories; access a private repository without authentication behaves the same as an attempt to access a repository that does not exist.

Leave a ReplyCancel reply