Search code examples
gitsshcmdgit-remote

How to connect to local git repo on another disk?


I have a local source git repo C:\Users\qweta\Documents\scrmd.git\ and a local blank repo D:\syb\loc.

I want to add srcmd.git as a remote repo in loc. The adding seems to work:

D:\syb\loc master ❯ git remote add origin "C:\Users\qweta\Documents\scrmd.git\"
D:\syb\loc master ❯ git remote -v
origin  C:\Users\qweta\Documents\scrmd.git" (fetch)
origin  C:\Users\qweta\Documents\scrmd.git" (push)

But git remote show and git fetch origin give the same error:

D:\syb\loc master ❯ git remote show origin
ssh: Could not resolve hostname c: Name or service not known
fatal: Could not read from remote repository.

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

Can you give some advice on how to solve this?

My system: Windows 10

My terminal: Command Prompt in Windows Terminal, the master thing in user prompt is added by clink and oh-my-posh extensions to work with git.

This problem doesn't exist when I try to add it to remote reference in a git folder in C:\SOMELOCATION.


Solution

  • It is an issue with the syntax for remote urls:

    with C:\User\... (a string starting with no protocol prefix and a <server>:... pattern), git interprets this as an ssh url to a server named C.

    One possible fix is to explicitly write a file://... url, something like :

    file://C:/User/qweta/Documents/scrmd.git/
    # or
    file:///C/Users/qweta/Documents/scrmd.git/
    

    I do not have a windows system at hand to confirm the following:

    • git may also accept:
    /C/User/qweta/Documents/scrmd.git