Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git does not require a .git extension when cloning from GitHub. Is this a feature of Git or of GitHub?

Tags:

git

http

github

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.

like image 842
Rob Rose Avatar asked Mar 09 '18 02:03

Rob Rose


4 Answers

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.

like image 53
Matt Avatar answered Oct 15 '22 08:10

Matt


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.

like image 28
shafrianadhi Avatar answered Oct 15 '22 10:10

shafrianadhi


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.

like image 28
Andreas Badelt Avatar answered Oct 15 '22 10:10

Andreas Badelt


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
like image 36
jsha Avatar answered Oct 15 '22 08:10

jsha