其他分享
首页 > 其他分享> > Mr.Alright---一文完美解决git提交代码到github需输入账号密码的痛

Mr.Alright---一文完美解决git提交代码到github需输入账号密码的痛

作者:互联网

# 先使用ssh clone代码库

huang@MS-F0201-SH1SW MINGW64 /e/asProject
$ git clone git@github.com:xxx/test.git TestGithub
Cloning into 'TestGithub'...
kex_exchange_identification: read: Software caused connection abort
banner exchange: Connection to 13.250.177.223 port 22: Software caused connection abort
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

# 报错了,这应该是因为我公司网管做了限制,这个时候我切换成了https

huang@MS-F0201-SH1SW MINGW64 /e/asProject
$ git clone https://github.com/xxx/test.git TestGithub
Cloning into 'TestGithub'...
Logon failed, use ctrl+c to cancel basic credential prompt.
warning: You appear to have cloned an empty repository.

# 克隆成功了,创建个文件

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ touch a.txt

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git add .;git commit -am "add a.txt"
[master (root-commit) d6efbf0] add a.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt

# push的时候,什么鬼,尼玛,又让输密码,好难受啊
huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git push
Logon failed, use ctrl+c to cancel basic credential prompt.
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 205 bytes | 205.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/xxx/test.git
 * [new branch]      master -> master

输密码的痛,clone的时候来一遍
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
push的时候还得再输一遍,曹操曹操

那么怎么办呢? 一般有两种方法

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ touch b.txt

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git add . ; git commit -am "add b.txt" ; git push
[master ac73c13] add b.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 b.txt
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 398 bytes | 398.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/Mr-Smile/test.git
   d6efbf0..ac73c13  master -> master

一次性成功,没有再输入密码了,这下舒服了
在这里插入图片描述

我这是公司不能用ssh,那我家里能用,我想从https切换回ssh怎么办呢?.

从https切换成ssh

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git remote -v
origin  https://xxx:pwd@github.com/xxx/test.git (fetch)
origin  https://xxx:pwd@github.com/xxx/test.git (push)

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git remote remove origin

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git remote add origin git@github.com:xxx/test.git

huang@MS-F0201-SH1SW MINGW64 /e/asProject/TestGithub (master)
$ git remote -v
origin  git@github.com:xxx/test.git (fetch)
origin  git@github.com:xxx/test.git (push)

看到变成git@开头的,说明成功了,也可以查看config文件确认,修改后如下
在这里插入图片描述
Git的这技能,你get到了吗?要是这还是不会,请按下图操作
在这里插入图片描述

标签:F0201,git,MS,github,---,TestGithub,master,huang
来源: https://blog.csdn.net/Keep_Holding_On/article/details/114700338