单个设备中有多个git用户 [英] Multiple git user in single device
问题描述
我使用公司的笔记本电脑来存放公司的东西,但有时我也想用它来编写我自己的副项目.现在,我的git已配置为使用公司的git帐户,如何在一个设备上使用多个帐户?请注意,我的公司和我的附属项目也正在使用bitbucket.
I use my company laptop for company stuff but sometime I would also want to use it to code my own side project. Now my git is configured to use company's git account, how can I use multiple accounts in one device? Note that my company and my side project is using bitbucket too.
还是我应该在Mac中创建另一个用户,一个用于公司人员,另一个用于个人人员?
Or I should just create another user in mac, one for company stuff one for personal stuff?
推荐答案
这取决于您访问远程存储库的方式
It depends on how you access the remote repo
- https:确保将您的个人用户帐户添加到远程回购URL:
https://me@bitbucket.org/me/myrepo
.
然后使用凭据帮助程序来获取凭据(登录名/密码). - ssh:您可以配置多个私钥,一个私钥链接到一个专业帐户,一个私钥链接到一个个人帐户,所有私钥均在
~/.ssh/config
中引用.
参见" MacOS终端:如何使用第二个ssh密钥?".
- https: make sure add your personal user account in the remote repo URL:
https://me@bitbucket.org/me/myrepo
.
Then use a credential helper to cahce the credentials (login/password). - ssh: you can configure multiple private keys, one linked to a professional account, one linked to a personnal account, all referenced in
~/.ssh/config
.
See "MacOS Terminal: how to use a seccond ssh key?" as an example.
确保在您的个人存储库中设置正确的user.name/user.email
Make sure, within your personal repo, to set the right user.name/user.email
cd /my/repo
git config user.name myName
git config user.name myPersonal@Email.com
这不影响身份验证,但很重要,以便使您的提交反映谁"提交.
That does not influence the authentication, but matters in order for your commits to reflect "who" commit them.
这篇关于单个设备中有多个git用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!