1

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.

  • it should not have a trailing slash after the `.git`. Git origin expects a URL, not a file path. – Raptor Apr 13 '23 at 04:08
  • 2
    it's just an issue with the syntax you use to point at the directory. Try something like: `file://C:/Users/qweta/Documents/scrmd.git/` or ``file:///C/Users/qweta/Documents/scrmd.git/`` – LeGEC Apr 13 '23 at 04:30
  • These methods do work but the first one of @LeGEC 's. Thank you guys! – PineapplePie Apr 13 '23 at 06:16
  • But I wonder why this is not a problem when the source directory and the destination directory are in the same disk, namely the `C:\` disk? – PineapplePie Apr 13 '23 at 07:27

2 Answers2

1

But I wonder why this is not a problem when the source directory and the destination directory are in the same disk, namely the C: disk?

Your remote ends up with an extra trailing "

origin  C:\Users\qweta\Documents\scrmd.git"
                                         ^^^

That is because Git bash has escaped the trailing double-quote when interpreting \":

git remote add origin "C:\Users\qweta\Documents\scrmd.git\"
                                                         ^^^

While this would have worked:

git remote add origin "C:\Users\qweta\Documents\scrmd.git\\"
                                                         ^^^

This is only if scrmd.git is a folder representing a bare repository, and even then, you would not need the trailing \ anyway.

As commented, using a file protocol URL scheme file://C:/Users/qweta/Documents/scrmd.git/ is also an even more valid solution.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Good perspective! Miserably, I didn't even notice this trailing `"`, lmao. – PineapplePie Apr 13 '23 at 16:19
  • What if I have a repository on a Windows machine on a local network? On that machine I have initialized a bare repo, `C:\gameland.git`. On my dev machine, I tried `git remote add @:/C:/gameland.git` and all variation of that I can think. It gives ` ''/C:/gameland.git'' does not appear to be a git repository`. I'm not using quotes when I add the remote and I am using Windows cmd, not git bash. when I put `file://` or `file:///` in front, it gives `'//@:/C:/gameland.git' does not appear to be a git repository` – PHaZerous Jul 05 '23 at 03:31
  • @PHaZerous To my knowledge, a UNC path ([Git local protocol](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_local_protocol)) does [not support authentication](https://superuser.com/a/344933/141). No need for `username@`. As long as you can access a UNC path (`dir \\server\drive\path`), you can add it as a remote. The `file://` is supported [since Git 2.24](https://stackoverflow.com/a/58245916/6309). – VonC Jul 05 '23 at 05:01
1

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
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Thank you for answering! I tested all these methods again, all works except for the last one. Maybe I made a mistake earlier today when testing the `file://` method. And for later reference for other folks, check this answer for more details: [Difference between "file:///" and "file://"](https://stackoverflow.com/questions/25354048/difference-between-file-and-file) – PineapplePie Apr 13 '23 at 16:16
  • Ok, thanks for checking :) I deleted the one that doesn't work – LeGEC Apr 13 '23 at 16:57