一、设置用户名和邮箱
全局设置:
$ git config --global user.name "xxxx"
$ git config --global user.email "xxxx"
项目单独设置:
$ git config user.name "xxxx"
$ git config user.email "xxxx"
查看全局配置:
$ git config --list
查看当前项目配置:
方法一:
$ git config --local --list
方法二(项目根目录下):
$ cd .git
$ cat config
方法三:
$ git config user.name
$ git config user.email
二、配置多个SSH秘钥
在公司电脑上,有时需要同时访问公司私有gitlab和个人github仓库,用到的ssh秘钥不同,需要以下简单配置。
- 利用公司邮箱生成的ssh密钥对
id_rsa及id_rsa.pub - 利用个人邮箱生成ssh密钥对
id_rsa.github及id_rsa.github.pub - 将上述密钥对的公钥
id_rsa.pub及id_rsa.github.pub分别配置到gitlab及github平台上。 - 进入
~/.ssh/目录,执行touch config创建config文件,执行vim config,添加如下内容:
按下Host *github.com User ### // 用户名 HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.github ServerAliveInterval 300 ServerAliveCountMax 10ESC,输入:wq,(保存并退出)即可。
撤销新仓库的首次commit
git update-ref -d HEAD