search

Home  >  Q&A  >  body text

github - git两个.ssh key如何解决冲突

目前我使用github还有公司的gitlab,而github上对应的是我的QQ号,gitlab对应的是公司的账号。而且我不想在Github上添加公司的账号来获取的密钥。
解决问题: 参考网上文章,本地写了config文件

  # gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa(对应公司的账号)

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa2(我的QQ号)

情况说明:
1.出现的问题,目前公司提交的name居然是我的QQ信息,但是gitlab上添加的SSH key是公司对应账号生成的。(估计逻辑有点混乱)

2.我查看本地的配置cat ~/.gitconfig 是我QQ号对应的信息!

问题: 为什么gitlab上配置了公司账号的.ssh key,提交代码的时候还会显示QQ账号的信息?难道gitlab没有权限验证吗

阿神阿神2759 days ago605

reply all(2)I'll reply

  • 为情所困

    为情所困2017-05-02 09:31:48

    You may not understand the difference between push and commit

    push 是将本地库推送到远端,需要权限,sshkey是用来校验是否有push权限的
    commit 只是在本地将改动提交到本地的仓库,不需要权限。.gitconfig里面的用户名和邮箱只是commitThe information corresponding to the author does not have permission control function. You can specify it at will, even if you change it to Steve Jobs, you can submit it

    • git config user.name You can view the username configuration of the current repo

    • git log You can check the email address and user name used to submit historical commits

    ~/.gitconfig is the global configuration of your git. If there is no separate configuration under the project, it will be inherited from the configuration file

    Solution: Just configure it separately in the company project

    cd repo_of_work
    git config user.name 公司用户名
    git config user.email 公司邮箱

    In fact, this is still relatively easy to cause confusion. Once there is a new company project and you forget to configure the company email, a similar situation will occur. It is best to delete the global configuration. In this way, every time there is a new project, the user name and email address will not be configured. The email cannot be committed

    reply
    0
  • PHPz

    PHPz2017-05-02 09:31:48

    Supplementary instructions posted upstairs

    $ git config -l
    $ git config --global -l 
    $ git config --global --unset user.name
    $ git config --global --unset user.email

    reply
    0
  • Cancelreply