Git clone ssh with spaces in username, path and di

2020-04-11 08:03发布

I have quantity 3 windows 7 professional machines. Two are setup as development machines (one desktop and one laptop) with Git installed. The third is setup as a file server with Git installed plus it is also running as a ssh server.

I have been referring to the YouTube link Creating a Git Server on a Windows OS and I have successfully reached the 16:15 minute mark. To summarise up to this point in the video I have installed Git on all 3 machines, installed Bitvise SSH Server on the file server, created a --bare Git repository on the server and then tried to 'clone' the remote (file server) repository to a desktop folder.

My question is how do you articulate a Git command if there are spaces in the 'user name' and 'path' to the repo on the server? Additionally, the repo on the server is not on the C: drive. It is on the D: drive. Does this complicate things?

This is not just an exercise in using ssh over a LAN. I will be using this to access (pull and push) the repo from both the desktop and laptop whilst on the LAN and from the laptop whilst out and about (WAN) when needed.

I have tried the following and just about every combination thereof found on the internet without success:

git clone "ssh://user name@file-server/path to/repo"
git clone "ssh://user name@file-server/d/path to/repo"
git clone "ssh://user name@file-server/d:/path to/repo"

I am receiving the following error (when for example using the first line above):

fatal: '/path to/repo' does not appear to be a git repository
fatal: Could not read from the remote repository.

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

I know I have access rights as I am using the correct user name (and password when prompted for it) plus the 'Bitvise SSH Server Control Panel - Activity Log' indicates a successful login.

Connection from [{mac address}]:59251 logged in as Windows account 'FILE-SERVER\User Name'.

Additionally, the file servers (--bare) repository definitely exists in the "D:\path to\repo" directory.

hooks (dir)
info (dir)
objects (dir)
refs (dir)
config (file)
description (file)
HEAD (file)

Am I correct in wrapping the command in quotes?

Do I need to add '.git' to the end of the directory? EG: "repo.git". I noticed a lot of people do this. Is it personal preference, an unwritten standard or a requirement?

And lastly, when it comes to Git is the path case sensitive?

Thank's for any help.

标签: git ssh
4条回答
唯我独甜
2楼-- · 2020-04-11 08:16

Well, after some time I worked out how to accomplish this.

git clone "ssh://user name@file-server:/D/path to/repo.git"

Git at the command line is no different from any other command that has spaces in it. Enclose it in quotes... To be more specific, double quotes are less restrictive if using special characters.

Having a Git repository on a drive other than the default install (C:/) drive does not complicate things.

The file extension '.git' is required for it to work.

Is the path case sensitive? Well, when using windows case sensitivity is not a problem. But, for you to be correct and error free (especially between OS), it is always best to reflect the practice of case sensitivity. IE: 'A' is different to 'a'.

Finally, to reflect a different drive letter to that which Git is installed, place a colon between the computer name and the forward slash. This was the issue tripping me up.

I hope this information helps other.

查看更多
神经病院院长
3楼-- · 2020-04-11 08:16

Got the same problem in http cloning at Azure DevOps Server , Replaced all white spaces with "%20" Ex :-

git clone http://yourdomain/project%20collection/project1

try enclosing url with quotes plus spaces with %20 if above solution doesn't works.

查看更多
倾城 Initia
4楼-- · 2020-04-11 08:21

I have tried exactly the same and failed. The issue appears to be that a repo shall be on the c-drive on a windows platform.

I found no difference using either of

    git clone "ssh://<user name>@<file-server>/<path to repo>"
    git clone "ssh://<user name>@<file-server>/c/<path to repo>" <= note: changed 'd' to 'c'
    git clone "ssh://<user name>@<file-server>/c:/<path to repo>"

To get to a repo on other drives I solved it by using windows links and a folder helper on the c-drive:

    mkdir /<helper folder on c-drive>
    cd /<helper folder on c-drive>
    mklink /J <repo name> <drive letter>:/<path to repo>

Then clone from the helper folder

    git clone "ssh://<user name>@<file-server>/<path to helper folder>/<repo name>"
查看更多
▲ chillily
5楼-- · 2020-04-11 08:30

Yes, you have to repo.git in the end.

For example you can clone a existing git repository like this

git clone ssh://user@server:/GitRepos/myproject.git

查看更多
登录 后发表回答