Windows系统Git配置
一、Git配置
一般刚安装Git都要配置用户名和密码,因为你提交代码到本地仓库(上传代码到远程仓库)时会用到,如果没有没有配置,在你提交时它会提醒你的。
1、 Git的配置种类
Git的配置文件在控制台中使用 git config 命令用来修改配置,Git配置级别有3种,分别存在不同的配置文件中:
(1)仓库级别(当前仓库有效) local 〖优先级最高〗
$ git config user.name "testuser"
$ git config user.email [email protected]
(2)用户级别(当前用户有效) global〖优先级次之〗
$ git config --global user.name "testuser"
$ git config --global user.email [email protected]
(3)系统级别(系统全局有效) system〖优先级最低〗
$ git config --system user.name "testuser"
$ git config --system user.email [email protected]
2、 配置用户名和邮箱
$ git config --global user.name "testuser"
$ git config --global user.email [email protected]
二、Gitlab配置ssh key
很多公司都选择git作为代码版本控制工具,然后自己公司搭建私有的gitlab来管理代码,我们在clone代码的时候可以选择http协议,亦可以选择ssh协议来拉取代码。如何本地git客户端生成ssh key,然后配置在gitlab,而后使用ssh协议进行提交和拉取git远程仓库的代码。
1、打开本地git bash,使用如下命令生成ssh公钥和私钥对
$ ssh-****** -t rsa -C '[email protected]' (-C 参数是你的邮箱地址)
接着3次回车
2、然后用notepad++打开本地的~/.ssh/id_rsa.pub文件,复制其中的内容
3、打开gitlab,找到Settings-->SSH Keys--->Add SSH Key,并把上一步中复制的内容粘贴到Key所对应的文本框,在Title对应的文本框中给这个sshkey设置一个名字,点击Add key按钮
4、 再试一下拉取代码和提交代码,应该就不需要输入密码了