一. 清楚原有的全局配置
// 看一下是否配置过user.name 和 user.email等
git config --global --list
// 清楚全局用户名
git config --global --unset user.name
// 清楚全局邮箱
git config --global --unset user.email
//其他全部删除
git config --global --unset XXX
二、进入项目目录之下 给项目配置局部的git账号
- 配置局部用户名邮箱
git config --local user.name "xxxx"
git config --local user.email "xxxxx@xxx.com"
#完成配置后可以用git config --list 去查看
git config --local --list
- 全局配置git账号
```git`
git config --global user.name “chnnc”
git config --global user.email “ch_beam@163.com”
``
三、生成ssh密钥,生成的时候不要默认生成,取指定名字
- 一般生成ssh-key 默认生成两个文件 id_rsa id_rsa.pub
ssh-keygen -t rsa -C "你的邮箱地址"
id_rsa_company
四、生成好两个密钥之后,去.ssh 目录之下 新建config文件 无后缀
Host github.com
HostName github.com
User cy
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
Host github.com
HostName github.com
User chnnc
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_myself
Host ---------远端仓库的别名
HostName ---------远端仓库地址或IP(不支持配置端口)
User ---------仓库上的用户名
PreferredAuthentications ---------强制使用Publickey验证
IdentityFile ---------指向仓库私钥的绝对路径
Port ---------远端仓库端口,一般不需要设置,特殊情况除外
五、git操作规范
1.提交代码之前 commit > pull >push
要使用对应通道
https地址clone的不能使用ssh通道的地址提交!!!!!
配置ssh通道的提交只能使用ssh地址clone