16

I setup a git repo in foo

cd
mkdir foo
cd foo
git init

Now I want to reference that remotely

git clone git+ssh://me@somemachine/home/me/foo.git

fatal: git remote error '/home/me/foo.git' does not appear to be a git repository

So I take .git off and it works. But nearly every example I see has ".git" at the end. What does that ".git" mean?

Also, what's the difference between ssh://... and git+ssh://... (in both meaning and practical terms)

gman
  • 100,619
  • 31
  • 269
  • 393
  • Possible duplicate of [Why do some repository URLs end in .git while others don't?](http://stackoverflow.com/questions/11068576/why-do-some-repository-urls-end-in-git-while-others-dont) (which was asked later, but has a better answer). – blahdiblah Oct 07 '14 at 01:39

4 Answers4

16

What does that ".git" mean?

.git at the end of a git repository folder is just a naming convention that usually means that the folder is a server and not a client. I believe it's determined by the repository being bare or not (bare repositories have no working directory). The clone URL just points to a folder, if the actual folder has .git at the end, add it. Otherwise, don't.

Also, what's the difference between ssh://... and git+ssh://... (in both meaning and practical terms)

In practical terms they're pretty much the same. In meaning, they're using different protocols to connect to the server. ssh:// opens up an SSH connection to a server with a specific user and runs the git commands on the server (typically the server will restrict the commands by setting the user's shell to /usr/bin/git-shell). git+ssh:// means that the server is running git daemon locally and that clients need to first open an SSH connection to interact with the daemon.

Robert Rouhani
  • 14,512
  • 6
  • 44
  • 59
  • 1
    Also as a small note, `git+ssh://` is hardly ever used, and according to other answers, has been deprecated and removed from current versions of git. – Robert Rouhani Dec 31 '11 at 06:26
  • the folder is a server and not a client...what?! – robertmain Apr 10 '18 at 21:30
  • I believe what I meant was that it's a bare copy of the repo with the sole purpose of sharing (in the more centralized server/client setup that git is now almost exclusively used in), as opposed to a network of people with a checked out repo that are configured with each other as remotes (where the folder name typically does not end with ".git") – Robert Rouhani Apr 15 '18 at 19:10
  • Looking at my currently checked out repos with default settings, the .git suffix is stripped during a clone on Windows with git 2.12.2.windows.2 and on Ubuntu with git 2.7.4. By that I mean a repo in the form `https://github.com/foo/bar.git` when cloned in `~` will make the directory `~/bar/` and not `~/bar.git/`. I've observed this behavior from Github, Gitlab, and BitBucket, if this happens to be something that the server controls – Robert Rouhani Apr 18 '18 at 15:01
7

It's a common (but certainly not universal) convention that bare git repositories are created in directories whose names end with .git. That's the reason that you usually see .git at the end of repository URLs.

I'm not sure about the git+ssh scheme - in fact I can't find a reference to it in the git man pages. According to the Eclipse forums the protocol has been removed in favor of plain old ssh. (The Eclipse forums are of course not an official source of information about git, but that would make sense. I never knew what the difference was supposed to be anyway.)

David Z
  • 128,184
  • 27
  • 255
  • 279
3

The .git suffix is just convention to indicate that the directory in question is a bare git repository (ie, one in which there is no working copy). It's not actually required.

As for git+ssh://, according to the git-fetch manpage, it is not allowed:

Git natively supports ssh, git, http, https, ftp, ftps, and rsync protocols. The following syntaxes may be used with them:

  • ssh://[user@]host.xz[:port]/path/to/repo.git/
  • git://host.xz[:port]/path/to/repo.git/
  • http[s]://host.xz[:port]/path/to/repo.git/
  • ftp[s]://host.xz[:port]/path/to/repo.git/
  • rsync://host.xz/path/to/repo.git/

     An alternative scp-like syntax may also be used with the ssh protocol:>

  • [user@]host.xz:path/to/repo.git/
bdonlan
  • 224,562
  • 31
  • 268
  • 324
0

.git has no special meanings, weather you need to add it depends where the repo is located on server side, with or without .git.

sometimes a repo with .git imply it is a bare repo.

Zang MingJie
  • 5,164
  • 1
  • 14
  • 27