• Git配置多账户


    一般情况下,公司代码company_repos/会存放在公司内部的gitlab上,个人代码privacy_repos/会放在github上。因此我们会有两个git账户:公司账号zioyi@campany.com和个人账号zioyi@privacy.com。如果我们想把两者的账号区分使用,可以通过sshgit config来指定公司代码通过公司账号推,个人代码通过个人账号推,具体步骤:

    1.生成RSA公私钥

    要生成两组:公司的和个人的

    # ssh-keygen -t ras -C "{注册账号时用的邮箱}"
    > cd ~/.ssh
    
    # 公司的
    > ssh-keygen -t ras -C "zioyi@campany.com"
    # 然后在交互中设定文件名:id_rsa_gitlab
    
    # 个人的
    > ssh-keygen -t ras -C "zioyi@privary.com"
    # 然后在交互中设定文件名:id_rsa_githuab
    
    # 查看一下
    > ls
    config  id_ras_gitlab   id_ras_gitlab.pub
    id_ras_github   id_ras_github.pub   known_hosts
    
    # 配置Host
    vi config
    
    host gitlab.com
        Hostname gitlab.com
        User zioyi@company.com
        IdentityFile ~/.ssh/id_rsa_gitlab
    
    host github.com
        Hostname github.com
        User zioyi@privary.com
        IdentityFile ~/.ssh/id_rsa_github
    

    2.将公钥配置要gitlab和github的SSH-Key

    校验一下:

    > ssh -T git@github.com
    # Hi Zioyi! You've successfully authenticated, but Github does not provied shell aceess.
    
    > ssh -T git@gitlab.com
    # *** Weclome to Gitlab, zioyi ***
    # Unfortunately, interactive shells are disbaled.
    
    # 说明成功
    

    3.使用git config配置账户信息

    # 配置公司代码
    > cd /company_repos/repo1
    > git config user.name "Zioyi"
    > git config user.email "zioyi@company.com"
    # 会修改当前代码下的git配置 .git/config
    > cat .git/config
    [user]
            name = Zioyi
            emial = zioyi@company.com
            
    # 配置个人代码
    > cd privary_repos/repo1
    > git config user.name "Zioyi"
    > git config user.email "zioyi@privary.com"
    # 会修改当前代码下的git配置 .git/config
    > cat .git/config
    ...
    [user]
            name = Zioyi
            emial = zioyi@privary.com
    

    如果嫌一个一个配置太麻烦,可以设置全局配置user信息为个人账号,然后只需在公司代码中配置.git/config user信息为公司账号

    # 全局配置命令 更改 ~/.gitconfig
    > git config --global user.name "Zioyi"
    > git config --global user.email "zioyi@privary.com"
    > cat ~/.gitconfig
    ...
    [user]
            name = Zioyi
            emial = zioyi@privary.com
    

    大功告成!之后个人代码和公司代码的提交账号就可以区分使用了~

  • 相关阅读:
    汉英单词对照,汉英部分
    解密SQL Server存储过程等对象
    统计信息对执行计划的影响(二)
    统计信息对执行计划的影响(一)
    asp.net 避免 ajax 定时调用,利用 ashx 实现 long polling (长轮询)
    [ADO.NET][Command]如何抓取第一筆資料的第一個欄位或scalar值?
    鱼骨图
    js 中跳出多层循环
    IIS无法 添加/编辑 应用程序扩展名映射的原因
    如何让域名后面不显示xxx.do后缀
  • 原文地址:https://www.cnblogs.com/Zioyi/p/14798648.html
Copyright © 2020-2023  润新知