Discuss / Git / fatal: Could not read from remote repository. Please make sure you have the correct access rights...

fatal: Could not read from remote repository. Please make sure you have the correct access rights...

Topic source

我也遇到了fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.的问题,以下来自我的笔记:

廖老师是通过 git@github.com:michaelliao/learngit.git 关联的,我在win7和win10上测试推送时都不能成功,https的才可以。如果已经用git@关联,则可以在.git目录下的config文件中,把 url = 后面的内容改为https类型的即可。 https类型的格式为: $ git remote add origin https://github.com/daoke0818/testGit2.git

另外我发现:

如果在第一步中创建时已经初始化过项目,则这时会提醒 error: failed to push some refs to 'https://github.com/daoke0818/testGit2.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

因为远程库中已经存在readme文件了,所以需要先pull下来。命令如下: $ git pull origin master

这时又会报错: From https://github.com/daoke0818/testGit

branch master -> FETCH_HEAD fatal: refusing to merge unrelated histories 说这两个库有不相干的历史记录而无法合并,这时我们可以加上一个参数 --allow-unrelated-histories 即可成功pull: $ git pull origin master --allow-unrelated-histories

但是这时会可能会提示必须输入提交的信息,默认会打开vim编辑器,先按 i 切换到插入模式,写完后 Esc→:→wq 即可保存退出编辑器。如果不进入vim编辑器,则会自动生成一个合并代码的commit。然后再使用前面的命令push将本地提交推送到远程仓库。后面如果本地还有commit,就可以直接用 git push origin master 推送。

笔记地址: 文档:git学习(廖雪峰版教程).note 链接:http://note.youdao.com/noteshare?id=4653994abae090b764e7fb65a039a7fe&sub=4B72DD531A444C5E97EB28F6A969D01D

衬衫反穿i

#2 Created at ... [Delete] [Delete and Lock User]

谢谢老哥了!

cwli-cc

#3 Created at ... [Delete] [Delete and Lock User]

高手啊,兄弟

秃子念空

#4 Created at ... [Delete] [Delete and Lock User]

手动添加一个ssh公钥即可解决这个问题,具体添加ssh公钥的方法参见下方博客:

https://blog.csdn.net/u013778905/article/details/83501204

老哥你太棒了!

测试

fanfan太阳

#7 Created at ... [Delete] [Delete and Lock User]

我也遇到了这个问题,但我的config文件里面我没有url这个内容,那这种情况该怎么办啊?

Adorkable1

#8 Created at ... [Delete] [Delete and Lock User]

我也是在git上新建库时初始化了,再去本地git push就报错。后来我直接使用git push -f强推即可。

$ git push -u origin master
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 228 bytes | 114.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:Ms-Kelly-Yu/LeetCode.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

我win10的成功了,一开始一路回车,也是提示

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

之后仔细看了下,第4行询问是否继续连接时,我输入yes就OK了。

Fun_Traveller

#10 Created at ... [Delete] [Delete and Lock User]

git push -f 强推的老哥 可太秀了....好使!![捂脸]


  • 1
  • 2

Reply