美文网首页Android 进击
Git多个账户冲突问题解决

Git多个账户冲突问题解决

作者: 小程序猿一枚 | 来源:发表于2020-04-08 11:07 被阅读0次

    一台设备可能存在多个git账号,如何管理呢? 下面那两个git账号举例说明

    首先先注册账号
    第一个账号
    xxxxxx@qq.com(github.com )
    第一个账号
    xxxxxx@163.comgit.oschina.net

    步骤一、
    设置Git的user name和email:

        $ git config --global user.name "username"
        $ git config --global user.email "xxxxx@xxxxxxx.xxxx"
    

    步骤二、
    生成公钥
    git ssh 公钥生成

    注意重点
    在C:\Users\Administrator.ssh 目录下会发现 文件 enetic.pub 这就是第一个账号的公钥

    然后重复步骤一、步骤二生成第二个账号的公钥 enetic2.pub

    登陆对应账号(https://github.com/) 上传公钥

    步骤三 配置文件 配置主机host

    在C:\Users\Administrator.ssh 目录下新建文件config 添加配置信息如下:

    # 配置 xxxxxx@qq.com(gi)
    Host github.com            
        HostName github.com  
        IdentityFile C:\\Users\\Administrator\\.ssh\\enetic
        PreferredAuthentications publickey
        User username1
    
    # 配置git.oschina.net 
    Host git.oschina.net 
        HostName git.oschina.net
        IdentityFile C:\\Users\\Administrator\\.ssh\\enetic2
        PreferredAuthentications publickey
        User username
    
    

    mac 下配置

    # 配置 xxxxxx@qq.com(gi)
    Host github.com     
        HostName github.com
        IdentityFile /Users/用户名称/.ssh/enetic
        PreferredAuthentications publickey
        User username
    
    # 配置git.oschina.net 
    Host git.oschina.net 
        HostName git.oschina.net
        IdentityFile C:\\Users\\Administrator\\.ssh\\enetic2
        PreferredAuthentications publickey
        User username
    

    这样就配置完毕啦

    相关文章

      网友评论

        本文标题:Git多个账户冲突问题解决

        本文链接:https://www.haomeiwen.com/subject/dsizphtx.html