git - 如何解决远程 SSH 推送 github 错误
问题描述
我创建了链接到 github 的 SSH 密钥。我正在尝试将文件远程推送到创建的存储库
这些是我的代码
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/demo_repo2.git
git push -u origin main
但它给了我错误:
git@github.com:权限被拒绝(公钥)。致命:无法从远程存储库中读取。
请确保您具有正确的访问权限并且存储库存在。
我检查了 ssh 密钥是否已链接,确实如此。它甚至给
git remote -v
origin git@github.com:user/repo2.git (fetch)
origin git@github.com:user/repo2.git (push)
我尝试了几乎所有的答案,但没有奏效。请有人帮助我
解决方案
它不应该给你这个错误,因为你已经设置了一个 HTTPS URL:
git remote add origin https://github.com/username/demo_repo2.git
检查git config -l
任何url."git@github.com:".insteadOf https://github.com/
指令。
如果git remote -v
确实给了你一个 SSH URL,那意味着第一个git remote add origin
肯定失败了。
您可以强制使用 HTTPS URL:
cd /path/to/my/repo
git remote set-url origin https://github.com/username/demo_repo2.git
推荐阅读
- php - 如何从不使用 PHP Session 注销?
- python - 在 Python 中使用 googletranslate 包出错:期望值:第 1 行第 1 列(字符 0)
- python - Python重启后Gzip输出不同
- android - 如何从连接表中检索和列出数据到 firebase 中的 recyclerview?
- python - 如果 list = x 的任何值,请执行此操作
- ceph - ceph s3 radosgw 有多安全?
- perforce - 当存在一个不再存在的同名分支时分支 p4python
- c++ - `g++ -O3` 生成的 `xmm` 事物如何影响未排序数组的分支预测?
- php - 方法 App\Http\Controllers\VerifyController::update 不存在
- python - 将文件从 databricks dbfs / local 上传到 S3 存储桶。如何使用 boto3 库或挂载 s3 将文件从 databricks 上传到 S3 存储桶?