简体   繁体   中英

Cannot clone git repository does not appear to be a git repository fatal: Could not read from remote repository

I'm following git's doc to cretae a repository on a remote server on the local pc :

$ git clone --bare my_project my_project.git

I've copied the repository on the server

$ scp -r my_project.git myuser@myip:/opt/git

but if I try to clone

git clone myuser@myip:/opt/git/my_project.git

I get

fatal: 'opt/git/my_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
and the repository exists.

I though that it was a permission problem ,but if I connect with ssh myuser@myip I have no problem to create files o do anything ,the folder belongs to myuser.

First, check that your origin is set by running

git remote -v

This should show you all of the push / fetch remotes for the project.

If this returns with no output, skip to last code block.

Verify remote name / address

If this returns showing that you have remotes set, check that the name of the remote matches the remote you are using in your commands.

$git remote -v
myOrigin ssh://git@example.com:1234/myRepo.git (fetch)
myOrigin ssh://git@example.com:1234/myRepo.git (push)

# this will fail because `origin` is not set
$git push origin master

# you need to use
$git push myOrigin master

If you want to rename the remote or change the remote's URL, you'll want to first remove the old remote, and then add the correct one.

Remove the old remote

$git remote remove myOrigin

Add missing remote

You can then add in the proper remote using

$git remote add origin ssh://git@example.com:1234/myRepo.git

# this will now work as expected
$git push origin master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM