PS:博主为什么要改成ssh方式提交代码呢?还不是每次使用https协议提交的时候都要输入账号和密码,这也太麻烦了啊!!!
步骤一、使用git生成ssh密钥
不知道有没有ssh密钥的可以进入C:\Users\你的电脑用户名.ssh 查看有没有.ssh文件
生成步骤:
- 打开Git Bash。
- 将以下文本粘贴,替换为您在GitHub上的帐户的电子邮件地址。
ssh-keygen -t ed25519 -C "your_email@example.com"
注意:如果使用的旧系统不支持Ed25519算法,请使用:
$ ssh-keygen -t rsa -b 4096 -C “your_email@example.com”
- 使用提供的电子邮件作为标签,这将创建一个新的ssh密钥。
Generating public/private ed25519 key pair.
- 当提示您“输入要在其中保存密钥的文件”时,请按Enter。这接受默认文件位置。
Enter a file in which to save the key (/c/Users/you/.ssh/id_ed25519):[Press enter]
- 在提示符下,键入一个安全的密码短语,这个密码会在你拉取和推送代码时使用,可以不设置
Enter passphrase (empty for no passphrase): [Type a passphrase]
步骤二、将ssh密钥添加到github中
添加步骤:
- 复制刚刚生成id_rsa.pub
- 进入settings
- 点击SSH和GPG密钥
- 单击“新建SSH密钥”
- 输入一个自定义标题和粘贴刚刚生成的id_rsa.pub里面的内容
步骤三、修改git的remote url
- 使用命令 git remote -v 查看你当前的 remote url
$ git remote -v
- 复制项目的ssh路径,使用git remote set-url 修改路径
git remote set-url origin 项目ssh路径
额外步骤(有git小乌龟)
- 修改ssh客户端路,进入设置,点击网络,修改SSH客户端路径为git\user下的ssh.exe