git - 在 GITHUB 上从 https 迁移到 ssh
问题描述
我查找了其他问题,但没有得到与答案提供的相同结果。
我最初使用 https 使用 github 存储库备份了我的 DigitalOcean droplet。
我已遵循https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/about-ssh上的所有说明(多次)
我已经删除了旧的 .git 文件夹。我根据以下内容更新了 ~/.ssh/config 文件: 如何在 Ubuntu 上使用 ssh-add 永久添加私钥?
每次我推送或“git push --set-upstream origin main”时,我都可以选择输入我的用户名和密码,然后因为使用 https 而被拒绝。
我还将我的 ~/.ssh/config 文件更新为:
HostName github.com
User git
IdentityFile ~/.ssh/yourPrivateKeyName
IdentitiesOnly yes
解决方案
要从 https 迁移到 ssh,您只需要一个
# replace <your-name> and <your-repo> with the real values.
git remote set-url origin git@github.com:<your-name>/<your-repo>.git
但是,为方便起见,您可以克隆一个新的本地存储库。
只需键入
# replace <your-name> and <your-repo> with the real values.
git clone git@github.com:<your-name>/<your-repo>.git my-new-local-repo
推荐阅读
- r - 如何从 R 中的绘图元素中提取原始数据
- php - 如何链接到 ACF 关系“父级”
- tfs - 使用 TFS API 获取测试用例结果/结果
- python - 使用 postgresql 和 sql alchemy 在 python 中绑定聚合函数
- vba - 将数据从多个工作表复制到excel vba中的主工作表中
- node.js - 我在使用 Promise 摆脱异步效果时遇到了麻烦
- xml - 从文件中获取 XML 映射并将新数据导出到 XML - 由于错误而无法工作
- javascript - JQuery、FileSaver 和 SheetJS
- hyperledger-fabric - 订购服务是做什么的?
- c# - C# ssh.net 库,cd 命令不起作用(无法发送“/”)