git config —global_Git多用户配置

69fa782815ecbc8f7c7a737182d3d90d.png

备注

  • 如下的操作,Windows系统建议在Git bash工具里操作。
  • 如下操作的原理,建议查阅官方文档。Git - Reference

1.取消全局设置的用户信息。

Git命令:

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

2.本地生成多key

目前假定生成2个key,一个用于GitHub一个用于GitLab.

在生成sshkey时注意key的命名即可,然后各自对应添加到GitHub和GitLab账号中。

比如生成:

~/.ssh/id_rsa_github
~/.ssh/id_rsa_gitlab

3. 启动ssh-agent

Windows系统查看或开启服务地址:

计算机管理-->服务和应用程序-->服务-->OpenSSH Authentication Agent-->(麻烦自己开启)

Linux系统

ssh-agent 命令开启

4.家目录下添加Git对账号的配置

文件1

# vim ~/.gitconfig

[core]
        autocrlf = false
[credential]
        helper = store
        useHttpPath = true
        httpusepath = true

文件2

# vim ~/.git-credentials
# username:password@git host

http://huangteng:password@gitlab.com%3a8090
https://tshuangteng:password@github.com

5.SSH配置文件添加所有用户信息

# vim ~/.ssh/config 文件
 
Host github
HostName github.com
User github_name
IdentityFile ~/.ssh/id_rsa_github

Host gitlab
HostName gitlab.com
User gitlab_name
IdentityFile ~/.ssh/id_rsa_gitlab

6.Git仓库目录下设置对应Git服务的用户信息

使用GitHub服务

# vim github_demo/.git/config

[user]
name = github_name
email = github_mail@github.com

使用GitLab服务

# vim gitlab_demo/.git/config 文件

[user]
name = gitlab_name
email = gitlab_mail@gitlab.com

7.愉快的Git起来吧!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值