Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if git repo is public with HTTP request

For my project, I need to know if a git repo is public or not to do some actions. I first thought to use HTTP request so I'm using postman and I tried with multiple URLs with HEAD method.

When I'm sending a request, I can't see what in the header can indicate me when it failed or not.

When I send a request to github for a private project, I'm receiving a the status 404 so it's perfect for me cause I know that is a private project.

BUT when I do this for gitlab, I'm receiving the status 200 then I'm redirected.

I would like to know if there is a solution for that.

like image 840
Nulji Avatar asked Mar 02 '19 14:03

Nulji


People also ask

How do I know if my git repo is public?

Under your repository name, click Settings. Under "Danger Zone", to the right of to "Change repository visibility", click Change visibility. Select a visibility. To verify that you're changing the correct repository's visibility, type the name of the repository you want to change the visibility of.

How do I see my git repository permissions?

Open Security for a repository You set Git repository permissions from Project Settings>Repositories. Open the web portal and choose the project where you want to add users or groups. To choose another project, see Switch project, repository, team. Open Project settings>Repositories.

Are all git repos public?

You can restrict who has access to a repository by choosing a repository's visibility: public or private. When you create a repository, you can choose to make the repository public or private.

Is git public?

GitHub is public Git hosting site for both public, open source projects and private, proprietary codes. GitHub is not open source. Free accounts (applicable to Open Source projects) have a soft limit of 1GB per repository.


1 Answers

Generally, the easiest way to do this is to perform a GET request after appending /info/refs?service=git-upload-pack to the URL. That's the endpoint which Git uses to get reference information.

If the repo is public, you'll get a 200. You'll likely get a 401 if the repository is private or doesn't exist. Most major hosting providers don't provide information about whether a private repository exists or not until after you've authenticated, so you'll get a 401 either way.

Note that you can't use a HEAD request; GitHub returns a 405 Method Not Allowed in that case.

Example: Open Source Repo: https://gitlab.com/gitlab-org/gitlab-ce.git

{GET}: https://gitlab.com/gitlab-org/gitlab-ce.git/info/refs?service=git-upload-pack

Example 401:

wget $URL
Connecting to gitlab.com (35.231.145.151:80)
Connecting to gitlab.com (35.231.145.151:443)
wget: server returned error: HTTP/1.1 401 Unauthorized

echo $?
1
like image 125
bk2204 Avatar answered Oct 11 '22 19:10

bk2204