GitHub如何知道我正在使用哪个帐户? [英] How does GitHub know which account I am using?

查看:91
本文介绍了GitHub如何知道我正在使用哪个帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个GitHub帐户,一个用于我的工作,另一个用于我的个人用途.在执行提交时,我想将两者分开.

I have two GitHub accounts, one is for my work and the other is for my personal use. I want to keep these two separate when I'm doing commits.

当前,我可以根据自己的工作/个人存储库在本地系统上的不同存储库中更改GitHub凭据.进入该存储库后,我将编写以下命令更改为该帐户:

Currently, I simply change my GitHub credentials when I can in different repositories on my local system based on whether is it a work/personal repo. Once I am in that repo, I write the following commands to change to that account:

git config --global user.name "myusername"
git config --global user.email [myemail]

然后我处理了我的git命令,它似乎工作正常.我仍然有一些问题,因为我认为这不是正确的处理方式.

Then I handle my git commands and it seems to work fine. I still have a few questions as I feel it's not the correct way to handle things.

1)如果我将我的git用户/电子邮件更改为我的工作仓库中的个人帐户并进行了提交,那么该提交将成功并进入GitHub吗?看来确实不知道. GitHub是否不会检查该帐户是否有权提交该存储库?

1) If I change my git user/email to my personal account in my work repo and made a commit, will that commit be successful and go through to GitHub? It seems like it does which I don't understand. Would GitHub not check to see if that account has permission to make a commit to that repo?

2)您能推荐一种更好的方法来处理我的工作/个人帐户之间的互换,以使两者完全分开吗?

2) Can you recommend a better way to handle swapping between my work/personal accounts to keep those two completely separate?

谢谢!

推荐答案

如果我将我的git用户/电子邮件更改为我的工作库中的个人帐户并进行了提交,那么该提交将成功并通过github吗?

If I change my git user/email to my personal account in my work repo and made a commit, will that commit be successful and go through to github?

是,但是它将归因于错误的电子邮件地址.参见 Github帮助 :

Yes, but it will be attributed to the wrong email address. See Github help:

如果您的提交未链接到任何用户,我们将显示灰色 他们旁边有Octocat徽标

If your commits are not linked to any user, we will display the grey Octocat logo beside them

git中的每个提交都用电子邮件地址标记.就GitHub而言,它可以是您想要的任何电子邮件地址.

Each commit in git is tagged with an email address. This can be any email address you'd like, as far as GitHub is concerned.

>答案在本地帐户之间快速切换.我喜欢更新 .git/config 的想法每个回购的.git目录中的文件,告诉git使用哪个电子邮件:

This answer goes over ways to quickly switch between accounts locally. I like the idea of updating the .git/config file in the .git directory of each repo that tells git which email to use:

[user]
    name = John Doe
    email = email@email.com

将其添加到您正在使用的每个存储库的.git/config文件中,并且git会根据每个存储库的电子邮件将提交内容归因于此.

Add that to the .git/config file for each repository you're working on and git will attribute your commits based on the per-repository email.

如果您想知道 Github 如何跟踪所有这些操作,可以通过

If you're wondering how Github keeps track of all this, it is done through something called email aliases.

这篇关于GitHub如何知道我正在使用哪个帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆