Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I git clone from a Windows machine over ssh?

Tags:

git

windows

ssh

I can do ssh windowsmachine from Linux to access a Windows machine, and from there I can git init --bare foo.git, telling me Initialized empty Git repository in C:/Users/unhammer/foo.git/

but how do I clone that from the unix side?

$ git clone ssh://windowsmachine:foo.git
Cloning into 'foo'...
fatal: No path specified. See 'man git-pull' for valid url syntax

$ git clone ssh://windowsmachine:C:\\Users\\unhammer\\foo.git
Cloning into '\Users\unhammer\foo'...
fatal: No path specified. See 'man git-pull' for valid url syntax

$ git clone ssh://windowsmachine:/foo.git
Cloning into 'foo'...
fatal: ''/foo.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.

and similar messages for /C:/Users/unhammer/foo.git and /C/Users/unhammer/foo.git and /Users/unhammer/foo.git.

Note the double single-quotes:

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

This doesn't happen when I try to git clone linuxmachine:/some/path/that/does/not/exist.git, then git uses single single-quotes. (Maybe that's the issue, git-for-windows or something applying extra quotes?)

like image 901
unhammer Avatar asked Dec 18 '18 13:12

unhammer


People also ask

How do I clone a git repository in putty?

Commands to clone locally and commit back online To commit the changes to your local GIT repository you can use the following command: git commit -a -m "Commit comment." The system will connect to the server and upload the files that have been modified on your local computer.


1 Answers

Following @phd's link to https://stackoverflow.com/a/8050564/7976758 I found a reference to https://stackoverflow.com/a/2323826/69663 with a workaround to the quoting issue. Here's what I did:

On Windows, open Git Bash and, in my homedir:

echo 'git-receive-pack "$@"' >grp.sh
echo 'git-upload-pack "$@"' >gup.sh

On Linux, clone specifying upload-pack:

git clone -u '"C:/Program Files/Git/bin/bash.exe" gup.sh' ssh://windowsmachine/c/Users/unhammer/foo.git
cd foo
git config remote.origin.uploadpack '"C:\Program Files\Git\bin\bash.exe" gup.sh'
git config remote.origin.receivepack '"C:\Program Files\Git\bin\bash.exe" grp.sh'

So the repo path is the one that Git Bash shows (/c/Users/$username/$repo), no colon anywhere.


https://github.com/PowerShell/Win32-OpenSSH/issues/1082 seems related.

like image 78
unhammer Avatar answered Oct 16 '22 18:10

unhammer