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

GitUrlGithubGit Clone

Git Problem Overview


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

  1. Without .git extension:

    git clone http://foo/repo
    
  2. With .git extension:

    git clone http://foo/repo.git
    

Git Solutions


Solution 1 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser496949View Question on Stackoverflow
Solution 1 - GitTodd A. JacobsView Answer on Stackoverflow