I noticed that when cloning a repo from GitHub, a URL missing the .git
extension at the end will still clone correctly.
So for example, this command:
git clone https://github.com/kach/nearley
Will function the same as this address:
git clone https://github.com/kach/nearley.git
Is this functionality provided by the Git command or is it handled by GitHub on the server side? And if it is a feature of GitHub, do they document this anywhere?
Also appreciated would be any statements on how or why they implemented this.
The .git
extension is indicative of a bare repository. What is a bare repository?
Git doesn't seem to care if you don't provide the .git
extension for a repository that is named that way, but if you do provide it and the repository doesn't have that extension, your clone will fail. It seems, therefore, that it is Git and not Github specifically that supplies this feature.
See this other question for a few more comments.
And the Git docs.
You can skip the .git, the git is a version control system, usually knows how to find the full repository path from its name alone (without '.git'). For example, the go get github.com/username/reponame command of the golang language: it will clone that repo, even without the extension. here the reference.
See this other question for a few more comments.
As @Matt has pointed out, git does not seem to care. However it seems to be handled by the client, and other client libraries like JGit do seem to care. It just cost me nearly an hour to find out why my Spring Config Server would throw this exception at startup:
NoRemoteRepositoryException: ... <some-repo-url>/git-upload-pack not found
git clone
with the same URL was working perfectly. It was simply the .git suffix missing in the repository URLs configured under spring.cloud.config.server
- I was too used to omitting that.
This is a feature of GitHub. When you run git clone https://github.com/example/path
, git automatically appends /info/refs?service=git-upload-pack
and fetches https://github.com/example/path/info/refs?service=git-upload-pack
.
GitHub doesn't actually offer the "smart HTTP" git transfer protocol at that URL, it offers it at the variant with .git in the name: https://github.com/example/path.git/info/refs?service=git-upload-pack
. However, as a special exception, if the User-Agent header contains git/
, GitHub will offer the smart HTTP transfer protocol by replying with Content-Type: application/x-git-upload-pack-advertisement
. Try it yourself with curl:
$ curl https://github.com/jsha/minica/info/refs?service=git-upload-pack -si | head
HTTP/1.1 404 Not Found
$ curl https://github.com/jsha/minica/info/refs?service=git-upload-pack -si -H 'User-Agent: git/1.0'
HTTP/1.1 200 OK
Server: GitHub Babel 2.0
Content-Type: application/x-git-upload-pack-advertisement
...
001e# service=git-upload-pack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With