Reputation: 590
I have some code where people submit git repo links.
The repo may be served over HTTPS with no authentication or HTTPS with basic authentication.
I want to check programmatically whether if I have access to the repo. I don’t want to run git clone
because it could be time-consuming to download the entire history. I’m trying to find the fastest way to test authentication.
Upvotes: 15
Views: 6812
Reputation: 139531
One route is git ls-remote
as in
$ if git ls-remote https://github.com/git/git.git >/dev/null ; then echo got it ; fi
got it
Upvotes: 16
Reputation: 118352
I would try the following:
Use git init
to initialize a new, scratch git repo.
Try using git remote add
, to attempt to add the remote repository.
Then, attempt a git remote show
.
If all of these steps succeed, this should be fairly conclusive that you have access to the repository, without doing a full clone.
Upvotes: 1