Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git多用户配置问题 #3

Open
thinkerou opened this issue May 8, 2018 · 0 comments
Open

Git多用户配置问题 #3

thinkerou opened this issue May 8, 2018 · 0 comments
Assignees
Labels

Comments

@thinkerou
Copy link
Owner

thinkerou commented May 8, 2018

背景:在使用Git时经常会碰到多用户问题,尤其是那些经常给github提交PR又要给公司提交PR的用户。如,在gitlab上有一个账户,同时在github上有一个账户,且想在一台电脑上同时对这两个git账户进行操作,这个时候就需要进行git多用户配置。

  • 异常表现:不进行git多用户配置时就会出现这样的场景,我的github帐号是thinkerou,可是我给github上的某个repository提交PR时却显示的是gitlab的账号tianou,这就是因为没有进行git多用户配置的现象。

配置步骤

  • 配置不同的ssh key,使用ssh-keygen命令产生两个不同的ssh key,操作如下:

    • 生成github的ssh key信息:
      ➜  cd ~/.ssh
      # 使用github上的邮箱生成github的ssh key
      ➜  ssh-keygen -t rsa -C "[email protected]"
      # 命名以便进行区别
      Enter file in which to save the key (/Users/ltc/.ssh/id_rsa): id_rsa_github
      # 将ssh key添加到SSH agent中
      ➜  ssh-add ~/.ssh/id_rsa_github
    
    • 生成gitlab的ssh key信息:
      ➜  cd ~/.ssh
      ➜ ssh-keygen -t rsa -C "[email protected]"
      Enter file in which to save the key (/Users/ltc/.ssh/id_rsa): id_rsa_gitlab
      ➜  ssh-add ~/.ssh/id_rsa_gitlab
      
  • 生成ssh key后,需要在github和gitlab上的profile中编辑ssh key,在github中是这样的:

    • 打开页面https://github.com/settings/keys
    • 点击New SSH key
    • ~/.ssh/id_rsa_github.pub里的内容拷贝到Key
    • 点击Add SSH key完成添加
    • 同理,gitlab上也是类似的操作
  • ~/.ssh目录下配置config文件,内容形如下:

    Host gitlab.com
    User tianou
    IdentityFile ~/.ssh/id_rsa_tianou
    
    Host github.com
    User thinkerou
    IdentityFile ~/.ssh/id_rsa_github
    
  • 配置从github上拉取的repository的grpc/.git/config的内容(以grpc为例),增加如下内容:

    [user]
      name = thinkerou
      email = [email protected]
    

    注意:以后每个从github上拉取的repository都需要添加如上信息!

@thinkerou thinkerou self-assigned this May 8, 2018
@thinkerou thinkerou added the Git label May 8, 2018
@thinkerou thinkerou changed the title Git multi-user configure Git多用户配置问题 May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant