如何在您的计算机上配置多个github帐户? [英] How to configure multiple github accounts on your computer?
问题描述
因此,我有我的工作计算机,该计算机已连接到终端上的GitHub Enterprise帐户(github.company.com
).现在,我也想在这里设置我的个人帐户(github.com
).
So, I have my work computer and that is connected to my GitHub Enterprise Account (github.company.com
) on the terminal. Now I want to set up my personal account (github.com
) on here too.
I've been following this tutorial - https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574
and on step 3 when I have to create my config file should my HostName
be github.company.com
or github.com
? Can I have any (meaningful) name for Host
? Also, what does User
here mean?
此外,如何在终端上的这两个帐户(即我的个人帐户和企业帐户)之间切换?在某些情况下,我需要从我的个人帐户中进行提交,然后将其余部分与企业帐户一起使用.
Also, how do I switch between both these accounts on the terminal - i.e. my personal and my enterprise account? There are certain things I need to commit from my personal account, and use the enterprise account with the rest.
推荐答案
在同一台PC上使用两个GitHub帐户的详细步骤如下:
Detailed steps to use two GitHub accounts on the same PC as below:
如果您已将SSH密钥添加到github.company.com帐户,则跳过此步骤.
If you already added the SSH key to your github.company.com account, then skip this step.
首先,使用ssh-keygen
在C:\Users\username\.ssh
中创建id_rsa
和id_rsa.pub
.
First, use ssh-keygen
to create id_rsa
and id_rsa.pub
in C:\Users\username\.ssh
.
然后,将id_rsa.pub file
的内容作为SSH密钥添加到github.company.com帐户中.
Then, add the content of id_rsa.pub file
as a SSH key in github.company.com account.
使用ssh-keygen -t rsa -C "email address for the personal github account"
,并将密钥保存在/c/Users/username/.ssh/id_rsa_personal
中.
Use ssh-keygen -t rsa -C "email address for the personal github account"
, and save the key in /c/Users/username/.ssh/id_rsa_personal
.
现在将id_rsa_personal.pub
文件的内容作为SSH密钥添加到您的个人GitHub帐户中.
Now add the content of id_rsa_personal.pub
file as a SSH Key in your personal GitHub account.
在C:\Users\username\.ssh
目录中,创建具有以下内容的config
文件:
In C:\Users\username\.ssh
diectory, create a config
file with below content:
Host github.company.com
HostName github.company.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
4.通过SSH协议使用两个GitHub帐户
您可以通过以下方式克隆您的github.company.com帐户:
4. Work with the two GitHub accounts by SSH protocol
You can clone your github.company.com account by:
git clone git@github.company.com:companyaccountname/reponame
然后通过以下方式将个人帐户添加为本地回购中的远程帐户:
And then add the personal account as a remote in the local repo by:
git remote add personal git@github-personal:personalaccountname/reponame
要通过以下命令将文件从个人帐户获取到公司回购中:
To get the file from personal account to company repo by below commands:
git merge upstream master --allow-unrelated-histories
# make changes
git add .
git commit -m 'add the changes from peronal repo'
git push origin master
要由个人仓库的提交者从本地公司仓库提交/推送更改,您只需要重新配置用户名和电子邮件,然后再在本地仓库中提交更改:
To commit/push changes from local company repo by the committer of the personal repo, you just need to re-config the username and email before committing changes in the local repo:
git config user.name <personal github account username>
git config user.email <email for login the personal github account>
如果要使用公司帐户提交更改,只需重新配置用户名并再次发送电子邮件,然后再提交更改.
When you want to commit changes with the company account, just re-config username and email again before committing changes.
这篇关于如何在您的计算机上配置多个github帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!