# 先使用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的时候还得再输一遍,曹操曹操
那么怎么办呢? 一般有两种方法
- 第一种是切换成ssh(这种对我来说行不通,因为网管限制了)
-
第二种是修改config
xxx:pwd表示的是你 github的 账号名
:账号密码,我们创建一个b.txt,再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到了吗?要是这还是不会,请按下图操作
更新:2021年9月6日20:13:14
github更新了规则,就是说现在不能用账号、密码提交代码了,需要使用,账号和token去提交,token的位置在
我们现在需要的格式是
git remote set-url origin https://<your_token>@github.com/<user_name>/<repo>.git
<your_token>:换成你自己得到的token
<user_name>:是你自己github的用户名
<repo>:是你的仓库名称
简单的说就是把放密码的地方换成token就好了
版权声明:本文为Keep_Holding_On原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。