场景
原本使用ssh,但是ssh突然使用不了,需要跟换https。或者反之。你都可以随意切换。
解决方法
修改远程仓库地址
- 修改命令
git remote set-url origin [url] # 直接修改远程仓库为https的地址
- 先删后加
$ git remote rm origin
$ git remote add origin [url]
- 直接修改config文件
以上进行git操作的时候,每次都需要密码,所以可以配置免密
- 新建文件并保存密码
$ touch ~/.git-credentials
$ vim ~/.git-credentials
- 添加内容
https://{username}:{passwd}@github.com
- 添加git配置
$ git config --global credential.helper store
如果想切回ssh,直接修改远程仓库的地址即可
例如:git remote set-url origin [ssh的url]