多git帐户设置

公司统一使用git 进行代码管理,有时候但愿使用github保存本身写的一些代码,添加多git帐户颇有必要git

方法:github

一、进入用户目录的.ssh目录(若是没有,本身新建)ssh

cd .ssh

 

二、设置公钥(直接回车默认生成id_rsa和id_rsa.pub,为了多帐号进行git代码处理,设置本身的路径。例如我这儿设置的是:id_rsa_githubspa

ssh-keygen -t rsa -C "email"

三、新建config文件code

Host xxx.com
        HostName xxx.com
        User xxx
        IdentityFile ~/.ssh/id_rsa

Host yyy.com
        HostName yyy.com
        User xxx
        IdentityFile ~/.ssh/id_rsa_github

Ok,能够同时往xxx.com和yyy.com两个地址提交和更新代码了。blog

另外,好多博文说须要设置config user.name 和 config user.emailit

通过实践,不设置也并没太大问题。可是提交时候,会使用默认设置的user.name做为提交者的信息class

通常状况下,能够设置global信息,同时,针对本身的个别git地址的项目,在项目中单独设置。email

全局设置配置

git config --global user.name "your_name"
git config --global user.email  "your_email"

若是单个git项目没有设置user.name和user.email的话,使用该设置做为默认设置。

 

对单个项目使用单独的配置

下载代码
git clone git@github.com:project
cd project
git config user.name "your_name"
git config user.email  "your_email"

OK,搞定

相关文章
相关标签/搜索