Git本地账户管理

2019-03-26  本文已影响0人  JillZsy

上传代码时发觉自己的名字闪亮亮的出现了。公司的git跟自己的git账户窜一起了。要改!

设置或修改用户名和邮箱

//全局
$ git config --global user.name "JillZsy"
$ git config --global user.email "...@.com"
//局部,某仓库内
$ git config user.name "JillZsy"
$ git config user.email "...@.com"
//查看配置信息
$ git config --list

多个账户

  1. 配置SSH
    因为global中已经有了公司的账号,再添加时在~/.ssh下添加。
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "...@.com"  //命名为JillZsy_rsa
//为了让SSH识别新的私钥,需加入到SSH agent中
$ ssh-add JillZsy_rsa

$ ls
JillZsy_rsa JillZsy_rsa.pub
github_rsa github_rsa.pub

将.pub文件内容添加到对应账号的github->SSH and GPG keys中

$ cat JillZsy_rsa.pub //获取.pub内容
  1. 配置config文件
    在~/.ssh下创建config。并配置。
$ touch config //创建
$ vim config

----config
#default github user
Host github.com
HostName github.com
PreferredAuthentications publickey
User ***
IdentityFile ~/.ssh/github_rsa

#JillZsy
Host JillZsyHost
HostName github.com
PreferredAuthentications publickey
User JillZsy
IdentityFile ~/.ssh/JillZsy_rsa
  1. 远程测试
$ ssh -T git@JillZsyHost //对应的Host名称
  1. 使用
//clone 可以直接使用Host
$ git clone git@JillZsyHost:JillZsy/Flutter-jsDemo.git

记得在本地仓库内设置对应的局部用户名和邮箱

上一篇 下一篇

猜你喜欢

热点阅读