git

一个git配置多个github账号

2018-12-18  本文已影响314人  辛德瑞拉Dangerous

一台pc上只安装了一个git,要配置2个github账号,并配合github Desktop使用。

没有找到.ssh文件

进入.ssh目录下,如果没有找到.ssh,查看是否被隐藏掉了;如果还是没有的话,执行下面命令

ssh-keygen -t rsa -C"你的github邮箱地址"

一路回车就行(默认私钥名称为id_rsd\公钥为id_rsd.pub\密码为空),就会在%HOMEPATH%路径下看到.ssh文件夹,

配置

# one                                                                       
Host onegithub
HostName github.com
User one
IdentityFile ~/.ssh/id_rsa_one
# second                                                                           
Host secondgithub
HostName github.com
User second
IdentityFile ~/.ssh/id_rsa_second
ssh-agent bash
ssh-add id_rsa_one
ssh-add id_rsa_second
Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.

git config user.email "你的第二个github邮箱地址"
git config user.name "second"

一些git命令

git log
git status
git commit -m "test"

git remote rm origin
git remote add origin git@kevinchengithub:blackkeydestiny/Netty-4.1.git

git push --set-upstream origin master

项目地址(注意项目地址的变化,在克隆时)

git@oliverchen01:OliverChen01/TESTProj.git
git@blackkeydestiny:blackkeydestiny/netty-4.1.git

个人配置

个人配置(内容注释了)

git config --list

[user]
    name = oliverchen
    email = oliverchen@hk1180.com

[user]
    name = kevinchen
    email = blackkey.destiny@gmail.com
    
1、

$ git config user.name "kevinchen"
$ git config user.email "blackkey.destiny@gmail.com"

ssh-keygen -t rsa -C "blackkey.destiny@gmail.com"   
id_rsa_blackkeydestiny_Github
ssh-add id_rsa_blackkeydestiny_Github 

2、
$ git config user.name "oliverchen"
$ git config user.email "oliverchen@hk1180.com"


ssh-keygen -t rsa -C "oliverchen@hk1180.com"    
id_rsa_oliverchen01_Github
ssh-add id_rsa_oliverchen01_Github

3、
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_blackkeydestiny_Github
$ ssh-add ~/.ssh/id_rsa_oliverchen01_Github

ssh -T git@github.com
ssh -T git@blackkeydestiny
ssh -T git@oliverchen01


git@oliverchen01:OliverChen01/TESTProj.git
git@blackkeydestiny:blackkeydestiny/netty-4.1.git
上一篇 下一篇

猜你喜欢

热点阅读