首页 > 解决方案 > 在 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

标签: gitgithubssh

解决方案


要从 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

在此处输入图像描述


推荐阅读