git在pull/push代码时,需要用户名密码或密钥publickey

问:git在pull(拉)/push(推)代码时,有的时候需要输入用户名,有的时候需要用密钥,怎么回事呢?

答:是因为用git remote设置远程仓库时候用了htts 或 ssh 不同访问方式造成的。

1.用https方式,每次访问需要输入用户名/密码

$ git remote add origin https://gitee.com/${用户名}/${仓库名}.git

如果嫌输入用户名密码麻烦,可以尝试用下面命令,保存输入过的用户名密码

$ git config --global credential.helper store

如果运行上面命令还是提示输入用户名密码,那么建议你删掉https方式的远程链接,改用SSH 方式

 

2.用SSH方式,则需要你提前把密钥加到gitee里

$ git remote add origin git@gitee.com:${用户名}/${仓库名}.git

 

查看远程仓库地址:

$ git remote -v

 删除远程仓库地址:

$ git remote remove origin

查看remote帮助信息:

$ git remote -h

 

安装密钥后,测试是否成功:

$ ssh -T git@gitee.com

 

 

https://blog.csdn.net/qq_37788558/article/details/78866051

https://www.w3cschool.cn/git/git-uroc2pow.html

https://www.pudn.com/news/6228d86b9ddf223e1ad22e57.html

 

posted @ 2022-08-26 23:26  悟透  阅读(4478)  评论(0)    收藏  举报