一般情况下,公司代码company_repos/会存放在公司内部的gitlab上,个人代码privacy_repos/会放在github上。因此我们会有两个git账户:公司账号zioyi@campany.com和个人账号zioyi@privacy.com。如果我们想把两者的账号区分使用,可以通过sshgit config来指定公司代码通过公司账号推,个人代码通过个人账号推,具体步骤:

1.生成RSA公私钥

要生成两组:公司的和个人的

# ssh-keygen -t ras -C "{注册账号时用的邮箱}"
> cd ~/.ssh # 公司的
> ssh-keygen -t ras -C "zioyi@campany.com"
# 然后在交互中设定文件名:id_rsa_gitlab # 个人的
> ssh-keygen -t ras -C "zioyi@privary.com"
# 然后在交互中设定文件名:id_rsa_githuab # 查看一下
> ls
config id_ras_gitlab id_ras_gitlab.pub
id_ras_github id_ras_github.pub known_hosts # 配置Host
vi config host gitlab.com
Hostname gitlab.com
User zioyi@company.com
IdentityFile ~/.ssh/id_rsa_gitlab host github.com
Hostname github.com
User zioyi@privary.com
IdentityFile ~/.ssh/id_rsa_github

2.将公钥配置要gitlab和github的SSH-Key

校验一下:

> ssh -T git@github.com
# Hi Zioyi! You've successfully authenticated, but Github does not provied shell aceess. > ssh -T git@gitlab.com
# *** Weclome to Gitlab, zioyi ***
# Unfortunately, interactive shells are disbaled. # 说明成功

3.使用git config配置账户信息

# 配置公司代码
> cd /company_repos/repo1
> git config user.name "Zioyi"
> git config user.email "zioyi@company.com"
# 会修改当前代码下的git配置 .git/config
> cat .git/config
[user]
name = Zioyi
emial = zioyi@company.com # 配置个人代码
> cd privary_repos/repo1
> git config user.name "Zioyi"
> git config user.email "zioyi@privary.com"
# 会修改当前代码下的git配置 .git/config
> cat .git/config
...
[user]
name = Zioyi
emial = zioyi@privary.com

如果嫌一个一个配置太麻烦,可以设置全局配置user信息为个人账号,然后只需在公司代码中配置.git/config user信息为公司账号

# 全局配置命令 更改 ~/.gitconfig
> git config --global user.name "Zioyi"
> git config --global user.email "zioyi@privary.com"
> cat ~/.gitconfig
...
[user]
name = Zioyi
emial = zioyi@privary.com

大功告成!之后个人代码和公司代码的提交账号就可以区分使用了~

Git配置多账户的更多相关文章

  1. 初次使用git配置以及git如何使用ssh密钥(将ssh密钥添加到github)

    初次安装git配置用户名和邮箱 初次安装git需要配置用户名和邮箱,否则git会提示:please tell me who you are. 你需要运行命令来配置你的用户名和邮箱: $ git con ...

  2. git配置SSH Key,上传本地代码至github

    git配置全局的name和email git config --global user.name "name" git config --global user.email &qu ...

  3. 初次安装git配置用户名和邮箱

    初次安装git配置用户名和邮箱 初次安装git需要配置用户名和邮箱,否则git会提示:please tell me who you are. 你需要运行命令来配置你的用户名和邮箱: $ git con ...

  4. Windows环境下Git配置及使用

    Windows环境下Git配置及使用 一.安装包位置 Git下载地址https://git-scm.com/download/win TortoiseGit下载地址https://tortoisegi ...

  5. git设置多账户

    1.设置公司gitlab 0.先给git 设置一个全局的账户, 如果是公司的电脑环境, 全局的账户当然是用你在公司的邮箱了 git config --global user.name "yo ...

  6. git使用,Git的skil-map,git配置http/https/socks5代理

    . 检出.克隆库: git clone git://git.openwrt.org/openwrt.git 2. git查看某个文件的修改历史 git log --pretty=oneline 文件名 ...

  7. git配置多个ssh key

    随着工作的深入,我们通常都会有多个git账户.比如公司gitlab一个账户,github或gitee有一个账户.而平时我们又回通过 配置ssh公私钥认证的方式省去繁琐的登录远程仓库的操作,不同的git ...

  8. PhpStorm Git 配置(解决文件没有变色的问题)

    摘要: PhpStorm Git 配置 首先需要安装windows下的Git版本,网上有很多我下载的是msysgit反正都差不多,不会的自己百度. 其次打开PhpStorm,点击File ,Setti ...

  9. Android开发之Git配置

    Android开发之Git配置 1.首先git配置: 输入命令: git config --global user.name "xxx.xx" git config --globa ...

随机推荐

  1. 网络损伤仪WANsim的队列深度功能

    什么是队列深度 在网络损伤仪WANsim中,队列是指一个用于缓存报文的缓冲池.深度是指缓冲池可以存储的最大数据量.当WANsim接受的报文超出了带宽限制的量时,溢出的报文会进入队列中. 我们可以在WA ...

  2. 动静态web项目(三)

    在Eclipse中将web项目分为了Dynamic Web Project和Static Web Project. 那么这两种有什么区别呢? 其实这里的Dynamic和Static是通过页面来区分的. ...

  3. Springboot+Mybatis+小程序

    思维导图: 项目效果图 一览界面: 新增界面:

  4. npm 报错 : npm ERR! Maximum call stack size exceeded

    解决方法:https://blog.csdn.net/caijunfen/article/details/81009797

  5. dva的effect那么难用,自己造一个轮子吧

    背景 对于dva这个开发框架,国内从事react的前端工程师多半不会感到陌生,dva完善的开发体系和简单的api,让其被广泛运用到实际工作中.我所在的公司也是长期使用dva作为基础的开发框架,虽然好用 ...

  6. 5G[generation]的知识收集

    一.什么是5G? G的英文是"5 Generation",即第五代无线通讯系统. 二.发展历程 1G的速率只有2.4k.2G是64k.3G是2M.4G{2013年12月,我国第四代 ...

  7. Django报错:'Specifying a namespace in include() without providing an app_name '

    环境:win10(64)+pycharm2018.3+python3.7 在网页项目中使用include()方法 项目目录中同时存在app/urls.py和proj/urls.py 在proj/url ...

  8. PHP判断访问者手机移动端还是PC端的函数

    *移动端判断*/ function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROF ...

  9. Genymotion模拟器安装ARM架构编译应用失败解决方案

    我们在安装一些应用到Genymotion模拟器会提示:adb: failed to install xx.apk: Failure [INSTALL_FAILED_NO_MATCHING_ABIS: ...

  10. 一些Shell脚本记录

    查看换行符 使用vim打开文件,输入:set ff?.根据返回结果可以文件类型 字符串 opcenter.sjb.bz [root@opcenter backup]# echo ${HOSTNAME% ...