新电脑重新配置git


前言

新买的电脑重新配置git


一、安装Git

Git官网地址:https://git-scm.com/

二、全局配置用户名和邮箱

1.配置用户名

git config --global user.name "xxx"

注:xxx可以随便自己起

2.配置邮箱

git config --global user.email "xxx@xxx.com"

三、生成ssh公钥并配置

ssh是Secure Shell(安全外壳协议)的缩写,建立在应用层和传输层基础上的安全协议。为了便于访问github(或gitee),要生成ssh公钥,这样就不用每一次访问github都要输入用户名和密码。

ssh-keygen -t rsa -C "xxx@xxx.com"

注:引号中的邮箱是你在 github(或者gitee)上注册所使用的邮箱

上述命令如果执行成功,会返回以下代码,表示设置存储地址

Generating public/private rsa key pair.

Enter file in which to save the key (c/Users/xxx/.ssh/id_rsa):

注:xxx 是你电脑的用户名

此时,直接回车。

回车后,会出现两种情况:

① 第一种:运行正常,直接回车

Enter passphrase (empty for no passphrase):

② 第二种:说明你已经设置了存储地址,我们输入“y”,然后回车

/Users/your username/.ssh/id_rsa already exists.

Overwrite (y/n)?y

以上任意两种情况之后,会出现:

Enter same passphrase again: 

此时,再次回车,会出现:

Your identification has been saved in /Users/xxx/.ssh/id_rsa.

Your public key has been saved in /Users/xxx/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:Cxl6JWOTXogvER2CG7R6qegvIZGf1jVNWFHuztRkuPg xxx

The key's randomart image is:

+--[ RSA 3072]----+

|    ...          |

|   o oo.         |

|  . .ooo.        |

|    o o+         |

|   . ..oS.       |

|    . . + .      |

|       . o .     |

|        . o+.    |

|         +E++.   |

+----[SHA256]-----+



这时候,SSH key 就生成了。文件目录是:/User/xxx/.ssh/id_rsa.pub。现在就可以将 id_rsa.pub 文件里的内容全选,添加到 github (或者gitee)的 SSH 公钥里。

四、验证 Git 环境是否配置成功

$ ssh -T git@github.com

或者

$ ssh -T git@gitee.com

备注:

① 当提示输入(yes/no)? 时,在后面输入 yes 回车即可,如果看到欢迎语 “Hi xxx! You’ve successfully authenticated, but GitHub does not provide shell access” 则表示配置成功。

$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (xxx.xx.xx.xx)' can't be established.
ED25519 key fingerprint is SHA256:+ULzij2u99B9eWYFTw1Q4ErYG/aepHLbu96PAUCoV88.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com' (ED25519) to the list of known hosts.
Hi xxxxxx! You've successfully authenticated, but GITEE.COM does not provide shell access.

② 如果提示类似 “ssh: Could not resolve hostname \342\200\223t: Name or service not known” 的错误,解决办法是执行命令:ssh -t -p 22 git@github.com(其中 -p 表示修改服务器端口为22)。

总结

以上就是今天要讲的,本文仅简单介绍了新电脑重新配置 git 的一些有关内容。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值