git 权限被拒绝(公钥)。致命:无法从远程存储库读取
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42544568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permission denied (publickey). fatal: Could not read from remote repository
提问by Mona Jalal
I have the following in my .git/config
我有以下内容 .git/config
1 [core]
2 repositoryformatversion = 0
3 filemode = true
4 bare = false
5 logallrefupdates = true
6 [remote "origin"]
7 url = [email protected]:monajalal/instagram-scraper.git
8 fetch = +refs/heads/*:refs/remotes/origin/*
When I am trying to push the changes to the master I get this error:
当我尝试将更改推送到主服务器时,我收到此错误:
$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have tried these both but still get error:
我已经尝试了这两个,但仍然出现错误:
2150 git remote set-url origin https://github.com/monajalal/instagram-scraper.git
2154 git remote set-url origin [email protected]:monajalal/instagram-scraper.git
mona@pascal:~/computer_vision/instagram/instagram$ git log
commit e69644389a5c7be65ae6eae14d74065e221600cb
Author: Mona Jalal <[email protected]>
Date: Wed Mar 1 17:48:00 2017 -0600
scrapy for instagram skeleton
mona@pascal:~/computer_vision/instagram/instagram$ git status
On branch master
nothing to commit, working directory clean
$ uname -a ; lsb_release -a
Linux pascal 3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
Please suggest fixes.
请提出修复建议。
采纳答案by Mona Jalal
Possibly not the best solution but considering there was nothing in the repository I had created in github I used the following command and it worked out:
可能不是最好的解决方案,但考虑到我在 github 中创建的存储库中没有任何内容,我使用了以下命令,结果如下:
git push -f origin master
回答by VonC
If you did not properly setup your ssh key with GitHub, you can at least try with https (which you mentioned):
如果您没有使用 GitHub 正确设置您的 ssh 密钥,您至少可以尝试使用 https(您提到的):
git remote set-url origin https://github.com/monajalal/instagram-scraper.git
That will ask for your username (monajalal
)/password of your GitHub account.
这将询问monajalal
您的 GitHub 帐户的用户名 ( )/密码。
That will work because you own that repository, meaning you have the right to push.
Make sure you have made a commit locally in order to push.
这将起作用,因为您拥有该存储库,这意味着您有权推送。
确保您已在本地进行提交以进行推送。
git add .
git commit -m "new commit"
git push -u origin master
The fact that you might be forced to do a git push -f
means the destination (the remote GitHub repo) is not empty but includes commits of its own (typically, a README.md
or a LICENSE
file)
您可能被迫执行某项操作的事实git push -f
意味着目标(远程 GitHub 存储库)不为空,但包含其自己的提交(通常为一个README.md
或一个LICENSE
文件)
In that case, it is best, with Git 2.9 or more, to do:
在这种情况下,最好使用Git 2.9 或更高版本:
git config --global pull.rebase true
git config --global rebase.autoStash true
Then
然后
git pull
That will replay your local commits on top of those present in (and fetched form) the GitHub repo.
这将在 GitHub 存储库中存在的(和获取的形式)之上重放您的本地提交。
Then a simple git push -u origin master
would work. No need to force push your history.
然后一个简单的git push -u origin master
工作。无需强制推送您的历史记录。