1

I am trying to use the git server docker image to set up a local git server.

My docker-compose config is this:

  git-server:
    image: jkarlos/git-server-docker
    restart: always
    ports:
      - "22:22"
    volumes:
      - ./docker/git-server/keys:/git-server/keys
      - ./docker/git-server/repos:/git-server/repos

With this setup, of the following two versions, the first one works while the second one does not.

git clone ssh://git@localhost/git-server/repos/my_repo.git
git clone git@localhost:git-server/repos/my_repo.git

The second version gives this error message:

Cloning into 'my_repo'...
fatal: 'git-server/repos/my_repo.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I had thought that these two versions were the same, but that's clearly wrong. What is the difference?

Stephan
  • 23
  • 4
  • 1
    "*…the second one does not [work]…*" In what way it doesn't? Connection error? Timeout? Any error messages? The difference between these syntaxes is that in scp-like syntax `user@host:path` you cannot use port; as you don't set port explicitly there should be no difference. – phd Nov 27 '22 at 14:54
  • Consider reading the docs: https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols Really quite helpful on this very point. – matt Nov 27 '22 at 14:58
  • 1
    Thanks for the link @matt "Or you can use the shorter scp-like syntax for the SSH protocol:" ... sounds like it is the client's choice and not affecting the server... which makes me more confused about why it doesn't work in my case – Stephan Nov 27 '22 at 15:51
  • 1
    This is weird and makes little sense to me. Especially given the link from @matt, I would have expected both syntaxes to be equivalent and to both work. I'm not familiar with this git server docker image but as far as I can understand it, both syntaxes should work. – joanis Nov 27 '22 at 16:02
  • 1
    I just noticed the error message complains about `my_repo` not appearing to be a Git repo, but your command says `my_repo.git`. Are you sure you have that `.git` extension in your clone command? On GitHub or GitLab, you have redirects that will add the extension automatically for you, but if you're using ssh to talk to a self-hosted repo, you need to provide the exact path, with the extension included. – joanis Nov 27 '22 at 17:11
  • @Stephan, I also noticed that git-server-docker is an old and unmaintained thing. The last update was five years ago, there are probably all sorts of reason it's not a very good choice, most likely including many unpatched vulnerabilities. See https://github.com/jkarlosb/git-server-docker/issues/30 for a possible alternative. – joanis Nov 27 '22 at 20:00

1 Answers1

3

the first one works while the second one does not.

git clone ssh://git@localhost/git-server/repos/my_repo.git

Yes, it accessed the absolute path /git-server/repos/my_repo.git

git clone git@localhost:git-server/repos/my_repo.git

It tries and access the relative path git-server/repos/my_repo.git

Using an absolute path should work better:

git clone git@localhost:/git-server/repos/my_repo.git
                        ^^^^

Or, if the repository is not at /git-server, but, /another/path/to/git-server/...

git clone git@localhost:/another/path/to/git-server/repos/my_repo.git
                        ^^^^^^^^^^^^^^^^^^^^^^
                        # full and complete path
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • If this answer is correct, then the documentation at https://github.com/jkarlosb/git-server-docker is misleading. They suggest uploading the Git repo to `~/git-server/repos` and then accessing them via `git clone ssh://git@:2222/git-server/repos/myrepo.git`, but according to your answer that syntax would expect `/git-server` to be the root of an absolute path, not one under `~/`. – joanis Nov 27 '22 at 19:55
  • @joanis True, it depends on the SSH server configuration, which can, [through forced command](https://stackoverflow.com/a/13320256/6309) interpreted the path differently. – VonC Nov 27 '22 at 19:57
  • Have you tested your answer with this git-server-docker? I assume it comes fully configured, being a docker recipe? I just realized it's ancient, though, I just commented under the question about why I'd stay away from this docker recipe in the first place. – joanis Nov 27 '22 at 19:58
  • @joanis No: I just point out that the first test I would do is to use the absolute path, with the `git@localhost:/...` syntax. – VonC Nov 27 '22 at 20:04
  • Thanks @VonC! The leading slash is indeed the difference. Once added to the second version, that syntax works too. Thank you! – Stephan Nov 27 '22 at 22:59