Why do some repository URLs end in .git while others don't?

后端 未结 1 1865
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 06:31

When I clone a repository, is there any difference between these two URLs?

  1. Without .git extension:

    git clone http://foo/repo
    
相关标签:
1条回答
  • 2020-12-08 06:53

    The convention is that the .git extension should be used for bare repositories, and left off of directories with a working tree. Git doesn't really care, but has a few convenience methods that make this fairly transparent.

    For example, if you have a repository named /tmp/foo.git and you call git clone file:///tmp/foo, Git will first try to find /tmp/foo. If it doesn't exist, it will try /tmp/foo.git instead.

    This does not work the other way around. If your directory is named /tmp/foo and you try to clone from /tmp/foo.git you will be told:

    fatal: '/tmp/foo.git' does not appear to be a git repository

    Most of the HTTP/HTTPS functionality is from your web server, not Git. Even if you're using Smart HTTP transport, I suspect most of the magic happens in a server-side LocationMatch directive. Theory aside, some quick tests against GitHub show that it works the same way as the SSH and Git procotols in that respect, but your mileage may vary on other web servers.

    0 讨论(0)
提交回复
热议问题