3

Im getting a Fatal Error when trying to clone a repo to a new directory. I can't see what I'm doing wrong.

Im on a CentOS server, at the command line running:

git clone git@github.com:MYUSERNAME/REPONAME.git newdirectory

I get the error:

fatal: Could not switch to 'git@github.com/MYUSERNAME': No such file or directory

newdirectory definitely exists, and the user I am logged in as has write permissions, and also has a github ssh key set up.

If i put something in the newdirectory

Anyone got any ideas I can try? Cheers


UPDATE: This is what happens if I try SSL based instead of SSH:

-bash-4.1$ git clone https://github.com/MYUSERNAME/REPONAME.git newdirectory Initialized empty Git repository in /var/www/html/newdirectory/.git/ error: The requested URL returned error: 401 while accessing >https://github.com/MYUSERNAME/REPONAME.git/info/refs

fatal: HTTP request failed

I think this is to be expected though, its a private github repo, Im not sure https works for private repos? Part of why I have always used ssh (successfully) in the past.

Rob
  • 500
  • 2
  • 6
  • 13
  • The https authentication works, if no authentication is given it should ask you for authentication when needed. The 401 would indicate that the user you are using to authenticate with has no access to the repository anymore. If this is not the case than I would suspect that there might be a problem on github's end. – Wolph Jun 27 '13 at 13:53
  • 1
    for anyone running into the 'No such file or directory' issue and are doing a `--sparse` clone, take a look at this question: https://stackoverflow.com/q/72223738. your git version may be too low – starwarswii Mar 08 '23 at 22:13

2 Answers2

4

Well, I seem to have fixed it. I'm not sure why I haven't needed it before and do now, but adding ssh:// seems to have solved my problem:

git clone ssh://git@github.com:MYUSERNAME/REPONAME.git newdirectory

Is that ssh:// prefix normally required?

thanks to @WoLpH for getting me to play with the urls!

Rob
  • 500
  • 2
  • 6
  • 13
2

I believe you forgot to authenticate with Github. Do you have a private key on that machine which has access to that Github repository?

To make sure the rest works, try a https checkout instead. If that works than you know it's the authentication you have to worry about.

Wolph
  • 78,177
  • 11
  • 137
  • 148
  • Yes, i have a ssh key set up, and it is copied to the github repo keys. As the same user on this server I have previously set up the same repo in different directories. I'm trying to do (from what i can see) exactly the same thing as before. In the other local git repo folders I can connect, pull, fetch etc without issue. – Rob Jun 27 '13 at 13:40
  • Either the url is wrong, the authentication is wrong or Github is having issues. I assume you cimply copied and pasted the https/git links from the Github page so we can probably rule that out. So authentication and github issues remain. – Wolph Jun 27 '13 at 13:54