Git通过配置config维护多个账号,区分个人账号和公司账号

1. 生成多个不同的sshkey秘钥

1.1 生成新的id_rsa公钥(个人)

ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/id_rsa

1.2 生成新的tc_pub公钥(公司)

ssh-keygen -t rsa -C "youremail@xxx.com" -f ~/.ssh/tc_pub

2. 在.ssh目录下新建一个config(无后缀文件)

(.ssh目录一般在C:/Users/xxx/.ssh目录)

# 个人account

Host github.com
HostName github.com
User CoderBruis

IdentityFile D:\MyConfiguration\TCLDUSER\.ssh\id_rsa
IdentitiesOnly yes

# 公司account

Host git.xxx.com
HostName git.xxx.com
User luohaiyang

IdentityFile D:\MyConfiguration\TCLDUSER\.ssh\tc_pub
IdentitiesOnly yes

3. 使用时不能设置全局username和email

取消设置全局的username和email

git config --global --unset user.name
git config --global --unset user.email

4. 在repo中使用不同的用户进行操作,进入repo目录后,需要先设置username和email,然后再进行其他操作

git config user.name CoderBruis

git config user.email "youemail"

然后查看该repo目录下,你的用户名和密码信息:

git config user.name

git config user.password

100. 命令总结

查看用户名 :git config user.name
查看密码: git config user.password
查看邮箱:git config user.email
测试ssh:ssh -T git@github.com

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在w11上配置多个git账号,可以按照以下步骤进行操作: 1. 首先,在用户文件夹中找到.ssh文件夹。如果没有该文件夹,可以手动创建一个新的文件夹,并将其命名为.ssh。[1] 2. 在.ssh文件夹中创建一个名为config的文件。这个文件将用于配置多个git账号的信息。 3. 打config文件,使用文本编辑器编辑该文件。在文件中,按照以下格式添加每个git账号配置信息: ``` Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_github Host github-second HostName github.com User git IdentityFile ~/.ssh/id_rsa_github_second ``` 这里的`Host`可以是你想要设置的任意名称,`HostName`是git的服务器地址,`User`是git的用户名,`IdentityFile`是私钥文件的路径。你可以为每个git账号设置不同的`Host`和`IdentityFile`。 4. 保存并关闭config文件。 5. 接下来,生成一个新的SSH密钥对。在终端中运行以下命令: ``` ssh-keygen -t rsa -C 'your_email@example.com' -f ~/.ssh/id_rsa_github_second ``` 这里的`your_email@example.com`应替换为你的邮箱地址,`id_rsa_github_second`是你为第二个git账号生成的密钥文件名。 6. 按照提示设置密钥的密码(可选)。 7. 将生成的公钥添加到你的git账号的设置中。 - 对于github.com,请将公钥内容复制到GitHub的SSH设置页面中。 8. 现在,你可以使用不同的git账号进行操作了。 - 当连接到第一个git账号时,使用`git@github.com`作为远程主机地址。 - 当连接到第二个git账号时,使用`git@github-second`作为远程主机地址。 注意:在进行git操作时,需要指定正确的远程主机地址以及相应的git账号信息。 这样,你就成功配置了w11上的多个git账号。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [如何配置多个git账号/多个远程仓库](https://blog.csdn.net/weixin_39729784/article/details/111726124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值