2

简而言之

目标:使用 ssh 而不是 https 执行一次成功的 git push。

问题: “错误:找不到存储库。致命:无法从远程存储库读取”。

分步背景

我正在使用 Ubuntu 远程服务器(DigitalOcean 的 droplet)和 Github 帐户。我在我的 Ubuntu 远程服务器上创建了一个 ssh 公钥,并用它在 Github 上创建了一个新的 ssh 密钥。然后我使用 git remote set-url 命令将远程的 URL 从 https 更改为 ssh:

git remote set-url origin git@github.com:[username]/[repository].git

之后,我测试了一切是否有效:

root@[DropletName]:/srv/test_git_folder# ssh -T git@github.com
The authenticity of host 'github.com (140.87.148.9)' can't be established.
RSA key fingerprint is SHA365:mVhbp6kXUbJWCl7E1IGOCspRamTxdCARLviWk6F5SY9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,140.87.148.9' (RSA) to the list of known hosts.
Hi [Username]! You've successfully authenticated, but GitHub does not provide shell access.

此时我尝试创建一个短文本文件...

root@[DropletName]:/srv/test_git_folder# nano testfile2.txt
[nano text editor appears; I input "Hello world!", save and close]

...并将其推送到 github

root@[DropletName]:/srv/test_git_folder# git add *
root@[DropletName]:/srv/test_git_folder# git commit -m "test push"
[master 5b6bcb0] test push
 1 file changed, 1 insertion(+)
 create mode 100644 testfile2.txt

但最后我收到一条错误消息:

root@[DropletName]:/srv/test_git_folder# git push –u origin master

ERROR: Repository not found.
fatal: Could not read from remote repository.

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

我该如何解决?

(我一直未能成功查看一些类似的问题,包括以下内容:-Git:无法从远程存储库读取 -CentOS :Git:“致命:无法从远程存储库读取” -git push 到远程存储库“可以未从远程存储库中读取” )

4

1 回答 1

0

首先,确保远程存储库确实存在并且首先在 GitHub 上创建。
看看是否可以在https://github.com/[username]/[repository]​​浏览页面

然后输入git remote -v/srv/test_git_folder检查 URL 是否正确(大小写相同,因为它区分大小写)

于 2019-06-10T06:26:58.293 回答