Windows配置多git帐号

1 前言

    若是咱们在公司有一个GitHub帐号,有一个私人的GitHub帐号,那平时在家工做时,就须要在电脑配置两个GitHub帐号才行,上教程git

2 过程

    2-1 生成秘钥github

        在某个文件夹打开gitbash窗口,执行下面命令:bash

# gh为名称,任意填写
git config --global user.name gh
# test@xxx.com 是登陆github等网站时的邮箱
git config --global user.email test@xxx.com

        而后:ssh

# test@xxx.com 是上面输入的邮箱
ssh-keygen -t rsa -C test@xxx.com

        结果以下图:网站

        第一个为输入的执行命令,第二个 ‘first’ 是输入的秘钥名称,不一样帐号应对应不一样名字,第三第四处红框直接回车,执行完毕后会在当前文件夹下生成 first 和 first.pub 两个文件:spa

    2-2 将秘钥放入我的设置.net

        以github为例,登陆 --> settings --> SSH and GPG keys --> New SSH keycode

        title: 随便填
        key:  将 first.pub 秘钥中的内容复制到里面教程

    2-3 重复上面两个命令,生成秘钥,而后放入网站get

    2-4 新建并修改 config 文件

        在 C:\Users\Administrator\.ssh 文件夹下创建 config 文件:

#first account
Host first
HostName github.com
User first
IdentityFile ~/.ssh/first

#second account
Host second
HostName github.com
User second
IdentityFile ~/.ssh/second

其中,HOST: 任意,
          HostName:    github --> github.com      码云 --> git.oschina.net
          User: 随意,我写的是 2-1 中的 user.name

          IdentityFile: ~/.ssh/xxx    xxx是秘钥文件中的文件名,即上面的 first

     2-5 clone 项目

          git clone git@first:用户名/项目.git

          其实就是用 config 中的 Host 代替 Hostname, 至关于给域名起了个别名

    2-6 默认帐号         电脑配置了度帐号以后,最近在公司push代码时用的老是私人帐号,发如今 C 盘我的用户目录下存在一个 .gitconfig 文件,能够进行相关配置

相关文章
相关标签/搜索