Is there a way to detect the provider of a Git repository based on the information available in a repo clone?

by Gabriel Petrovay   Last Updated October 18, 2019 21:26 PM - source

How can I detect what Git provider is available behind a certain "remote" (I can see it in the .git/config). I am talking here about on-premise installed Git servers where the domain names are not explicit enough (like

I want to know if I am working with a Gitlab or a Bitbucket server for example. The two products having different ways they work and different APIs. I would like to know for example which API to load when working with a certain Git repo. Or how to parse some commit messages that each Git provider generated differently.

Answers 2

Short answer: no.

From the git point of view there is no any API, only Git Protocol and all servers implement the protocol in (almost) the same way.

If you want to use server-specific API it's completely outside of git knowledge. You have to know what is the server and what version of API it implements. Or probe for known API endpoints and protocols.

October 18, 2019 21:04 PM

Based solely on the information in a repo clone, no, you can't. However, there are ways you can query the remote server to see what it might support.

For example, you could try the REST API endpoint for each server type and see what kind of response you get. You can also query the SSH endpoint for each server; the server version string will contain "babeld" for GitHub Enterprise, an OpenSSH string for GitLab, and usually something Java-based for Bitbucket Server.

There are also distinctive HTTP headers for some servers. You can tack on /info/refs?service=git-upload-pack to the end of the URL (which is the refs endpoint). GitHub will provide you a server header with GitHub Babel, GitLab may provide you with special GitLab headers, and Bitbucket may also provide identifiable headers (such as x-server).

In general, though, you can't parse commit messages based on the remote server type, since a particular project may have moved from one to another. That happens at various companies all the time, and for open source projects, too.

October 18, 2019 21:14 PM

Related Questions

How to restrict access to master branch on git

Updated October 13, 2018 04:26 AM

Git - multiple developers on same branch

Updated September 11, 2018 18:26 PM

How to integrate Bitbucket cloud with Concourse CI?

Updated August 14, 2017 00:26 AM