20

Anybody know how to checkout, clone, or fetch project or code from a git remote repository on a Windows server?

Repository IP is: xxx.xx.xxx.xx, source file directory is c:\repos\project.git

I am used to the command line interface from a SUSE Linux terminal. I have tried the same kind of method but it always replies that

fatal: ''/repo/project.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

Can anyone tell me how to setup and clone?

AsimRazaKhan
  • 2,154
  • 3
  • 22
  • 36
user1213492
  • 209
  • 1
  • 2
  • 4
  • 2
    So quote the exact command you tried. Without that it's not possible to tell what you are doing wrong. – Jan Hudec Feb 16 '12 at 10:01
  • 6
    Git, nor for that matter any other program, can't magically access files on disk of another computer unless you provide some access method to access them. Git can use 3 access methods: remote filesystem, ssh or http (web). Do you have any of those methods set up? If yes, edit the question to indicate how it's configured. Otherwise edit the question to ask how to set it up. – Jan Hudec Feb 16 '12 at 10:04
  • Note how it says /repo/project is not a repository. Maybe missing some escapes in the git call? – Daemon Painter Aug 14 '23 at 20:38

2 Answers2

10

You have to set up some kind of sharing from the windows machine, that you can access with git. Git supports 3 access methods: ssh, remote filesystem or http. The last one is probably most complicated, so I won't detail it. The first two are:

  1. Set up ssh server on windows.

    You can try this guide: http://www.timdavis.com.au/git/setting-up-a-msysgit-server-with-copssh-on-windows/. See also this question for some more options

    Update 2o23: Microsoft actually offers OpenSSH for Windows these days, including a service that you can just start to get a ssh server. Official guide starts here. It's a bit older version, but that only matters for exposing SSH agent to WSL2 and/or VMs.

    Than you clone by git clone username@xxx.xx.xxx.xx:/c/git/path/to/repo (you will be asked for password).

    Advantage of this method is that it's secure (connection is encrypted and ssh server is trustworthy), so you can use it over internet. Since git server is running on the windows machine during access, you can set up hooks for advanced security policy, controlling other processes and such.

  2. Share the repository using windows sharing.

    Than on the linux host, you need to mount the share with smbmount. That might require username and password, depending on how you set the permissions.

    Than you clone by git clone /share/mountpoint/path/to/repo.

    This is probably easier to set up, but it is not very secure, so it shouldn't be used outside local network. Also in this case hooks on the windows machine won't be executed (in fact git will try to execute them on the Linux machine, but they either won't run there or can be bypassed anyway), so you can't apply advanced security.

A particular file is not relevant, you need to give path to the directory containing .git subdirectory or to the directory that is a bare repository (path/to/repo above).

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • 1
    I tried the the command with the custom ssh port *ssh://user@xxx.xx.xxx.xx:xxxx/c/repos/project.git* But the repose with the error fatal: ''/c/repos/project.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 – AsimRazaKhan Mar 15 '18 at 05:41
  • @AsimRazaKhan I used UNC path following instructions here https://stackoverflow.com/questions/2519933/git-clone-repo-across-local-file-system-in-windows#2520121 This worked and met my needs. – Hezi Aug 15 '19 at 12:49
  • The timdavis.com link is dead. :/ – The incredible Jan Aug 14 '23 at 14:23
  • @TheincredibleJan it's an ancient answer. But recently I found that Microsoft themselves now provide Windows version of (somewhat older) OpenSSH, so I added the link to their documentation instead. – Jan Hudec Aug 14 '23 at 20:10
  • @JanHudec Thanks for the reply. I already set up the Windows OpenSSH. It works. But not for Git. :( I created a new bare repository on the server. When I try to clone it from my client I get: fatal: ''C:/Git/projects/HelloWorld.git'' does not appear to be a git repository fatal: Could not read from remote repository. – The incredible Jan Aug 15 '23 at 13:08
  • @TheincredibleJan the Git installer has an option to skip installing its own ssh (`/NoOpenSSH` IIRC) and then it will use the Windows one. – Jan Hudec Aug 15 '23 at 18:33
  • @JanHudec Problem was solved. I didn't try the bundled SSH from Git. OpenSSH was already installed on the server. The Git documentation unfortunately nowhere says anything about the Windows default shell not working with Git via SSH... https://stackoverflow.com/questions/53834304/how-do-i-git-clone-from-a-windows-machine-over-ssh – The incredible Jan Aug 16 '23 at 07:27
-1

First of all, the git repository is just a bunch of files you need to access. You wrote about cloning and fetching repository, and this is easy part - you just need to access the files (and have read rights).

It can be done by direct access to filesystem, by http(s) protocol, or by ssh connection. Actually, there is even a way to do it by ftp server.

What you can do:

1) set the ssh server, then access the git files via ssh server - actually, the path you should use depends on the ssh server you use on windows: source

2) set the web server to access the file: git clone http://host/path/to/repo

3) mount filesystem from windows on your linux machine and clone repo: git clone /mnt/filesystem/path/to/repo

Despite the method you choose I suggest to consult the apropriate chapter from Pro Git Book

  • I tried the the command with the custom ssh port ssh://user@xxx.xx.xxx.xx:xxxx/c/repos/project.git But the repose with the error fatal: ''/c/repos/project.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 – AsimRazaKhan Apr 03 '18 at 13:29
  • @AsimRazaKhan could you post the contents of the folder (does it contain .git folder) and access right for .git folder (if exists) – Michał Zabielski Apr 03 '18 at 13:34
  • yes it contains the .git inside /c/repos/project.git/.git – AsimRazaKhan Apr 04 '18 at 11:11