1

I've seen usage of the following git clone syntax

git clone --bare /path/to/repo /path/to/bare/repo.git

However, this doesn't seem to work when the destination is on a remote host. I've tried several formats for the destination—such as prefixing with ssh://, or user@—but all of my attempts have yielded folders created locally.

Obviously, I've found other approaches (https://stackoverflow.com/a/1402783/741970), but is there any way to use the above syntax?

Community
  • 1
  • 1
Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160

3 Answers3

1

I'm not a C guy, but poking around in clone.c's cmd_clone function, it doesn't seem so. The various help messages all use phrasing like git clone <repo> [<dir>], implying a simple directory name as the destination, and all of the operations on the destination side seem to be standard file operations, like recursive readdir and mkdir operations, while the repo stuff is couched in calls to transport.c, especially here, which calls to transport_get, which is all about URLs (file/git/ssh/etc).

You could set up an NFS share that points to a server (or a Dropbox folder), but that's probably not what you're after.

Community
  • 1
  • 1
Gary Fixler
  • 5,632
  • 2
  • 23
  • 39
1

That's impossible. Git does not yet have "create this repository on the remote host and then populate it using this history" in its protocol. I have seen this being discussed on tha main Git list, but the results were inconclusive (kind of "doable but no one needs this anyway so no one bothers to implement").

I should add that the approach suggested in the answer you linked to is pretty uh… strange, in particular the idea of first doing a local bare cloning.

What you should do instead is:

  1. Log in to the remote host via SSH.
  2. Create the remote directory using git init --bare. Make sure it has proper access permissions etc.
  3. Log out.
  4. Push what's needed from your local repository there. Usually this amounts to running

    git push <that_repo> +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
    

    If you intend to further communicate with that repository from your local repository you might consider first adding it as a named remote, like

    git remote add quux ssh://user@server/path/to/the/repo.git
    
kostix
  • 51,517
  • 14
  • 93
  • 176
1

you are inside out ... but you could remote execute the normal git clone command:

ssh user@remote.server git clone --bare user@local:/path/to/repo /remote/path/to/bare/repo

of course, NAT and permissions could make this impossible depending on your set up...

but to answer your question, no, you can't use the syntax you wanted to do the thing you want it to do.

underrun
  • 6,713
  • 2
  • 41
  • 53