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 git.company.com).
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.
Short answer: no.
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.
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
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.