window下git的用户切换_git多用户设置方法

git多用户设置方法

git多用户设置

生成ssh-keygen

通过ssh生成key(windows环境下,需要使用git bash)

注意:需要切换到用户目录进行操作(windows切换到用户目录)

$ ssh-keygen -t rsa -C "你的git帐号邮箱"

Generating public/private rsa key pair.

## 这里输入存储rsa文件的名称(多用户需要填写不同的名字)↓

Enter file in which to save the key (/d/Users/feng/.ssh/id_rsa):id_rsa_aliyun

## 这里设置密码(可不填)↓

Enter passphrase (empty for no passphrase):

## 重复密码(可不填)↓

Enter same passphrase again:

创建配置文件config

在~/.ssh目录下找到config文件(如果没有则创建一个,windows系统下目录地址为:C:\Users\你的用户名\\.ssh)gitlab

# 默认配置,一般可以省略

# 主机名字,不能重名

Host github.com

Hostname github.com

User 你的名称

Identityfile ~/.ssh/id_rsa

# 第二个配置

# 主机名字,不能重名

Host code.aliyun.com

# 主机所在域名或IP

HostName code.aliyun.com

# 用户名称

User 你的名称

# 私钥路径

IdentityFile ~/.ssh/id_rsa_aliyun

在git仓库中配置ssh-keys

查看.pub文件中的公钥,

cat id_rsa.aliyun.pub

并添加到仓库中的ssh-keys中(管理后台的sshKeys中)

测试

测试命令:

ssh -T git@code.aliyun.com

结果:

Welcome to GIT, 麦奇!

如果看到此命令,恭喜配置成功!!

遇到问题:

目前phpstorm无法使用内置的git进行更新提交代码

错误提示为:Could not read from remote repository.

解决办法:设置仓库级别的用户名和邮箱(必须切换到当前项目下)

设置方法:

切换到单个项目中设置相对应的账户和邮箱

// 设置仓库的user.email和user.name

git config user.email "你的邮箱"

git config user.name "你的用户名"

Everything Will Be Ok !

欢迎关注公众号:山脚下的乌龟

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值