Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

Context

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 (https://www.github.com/some_github_user/some_github_repository) and see whether the repository exists.

Question

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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 https://github.com/someperson/somerepo; then
  echo repository exists
else
  echo repository does not exist
fi

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading