mac版本的SourceTree切换帐号

问题场景

mac系统下:git

  1. 在souretree登陆gitlab帐号
  2. sourcetree原有的帐号没用或者被注销掉,须要切换帐号

经过以下步骤可成功切换到新帐号:shell

1、切换用户名和邮箱

git config --global user.name 查看当前用户名
git config --global user.email 查看当前邮箱

git config --global user.name "Your Name"  切换用户为您的用户名
git config --global user.email you@example.com 切换邮箱为您的git邮箱
复制代码

2、配置SSH key

  1. 检查是否是已经存在密钥(能进去说明已经存在,就删掉文件夹,从新建立):
cd ~/.ssh
复制代码
  1. 生成SSH密钥
$ ssh-keygen -t rsa -C “你的邮箱”//注意C必定要大写
复制代码

按3个回车,不设密码bash

文件存放位置 ~/.sshdom

  • 若是是window的话就在:C:\Users\Administrator.ssh 下面ssh

  • 若是是mac,在执行指令的目录(如mac打包机为:/User/zxl01/.ssh下)ide

  1. 当执行完2,则会输出以下:
Your identification has been saved in id_rsa. // 私钥
Your public key has been saved in id_rsa.pub. // 公钥
The key fingerprint is:
SHA256:IL6L2NjBQDAAuYfD6NzTbR8VIc/fJl1coDUhzL3LYP8 leyu@chargedot.com
The key's randomart image is:
+---[RSA 2048]----+
|B.       . +o.=o.|
|o.        +.o+.o.|
|o+  . .    oo  .o|
|*... . .   .+ + .|
|+o. o . S .. * = |
| = o o o .    *  |
|  o o . . .    . |
| = o .   .      E|
|o + .            |     
+----[SHA256]-----+
复制代码
  1. 设置公钥

打开公钥,复制公钥粘贴到 gitlab上设置 ssh Key 的地方gitlab

cat id_rsa.pub 
复制代码

打开gitlab-->点击Profile Settings,而后: spa

  1. 设置私钥
LELEdeMacBook-Pro:.ssh lele$ ssh-add id_rsa  // 添加私钥

Enter passphrase for id_rsa:  // 若是前面没有设密码,就不会有这个

Identity added: id_rsa (id_rsa) //出现这个,说明你成功设置了
复制代码
  1. 至此,配置完成,直接打开sourcetree便可正常操做

注意:一段时间后,若是出现提交或拉取代码失败,需从新在终端添加私钥便可.net

参考资料

Mac 下source tree 与 gitlab 添加 ssh 密钥3d

相关文章
相关标签/搜索