Git配置多账户
一般情况下,公司代码company_repos/会存放在公司内部的gitlab上,个人代码privacy_repos/会放在github上。因此我们会有两个git账户:公司账号zioyi@campany.com和个人账号zioyi@privacy.com。如果我们想把两者的账号区分使用,可以通过ssh和git 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配置多账户的更多相关文章
- 初次使用git配置以及git如何使用ssh密钥(将ssh密钥添加到github)
初次安装git配置用户名和邮箱 初次安装git需要配置用户名和邮箱,否则git会提示:please tell me who you are. 你需要运行命令来配置你的用户名和邮箱: $ git con ...
- git配置SSH Key,上传本地代码至github
git配置全局的name和email git config --global user.name "name" git config --global user.email &qu ...
- 初次安装git配置用户名和邮箱
初次安装git配置用户名和邮箱 初次安装git需要配置用户名和邮箱,否则git会提示:please tell me who you are. 你需要运行命令来配置你的用户名和邮箱: $ git con ...
- Windows环境下Git配置及使用
Windows环境下Git配置及使用 一.安装包位置 Git下载地址https://git-scm.com/download/win TortoiseGit下载地址https://tortoisegi ...
- git设置多账户
1.设置公司gitlab 0.先给git 设置一个全局的账户, 如果是公司的电脑环境, 全局的账户当然是用你在公司的邮箱了 git config --global user.name "yo ...
- git使用,Git的skil-map,git配置http/https/socks5代理
. 检出.克隆库: git clone git://git.openwrt.org/openwrt.git 2. git查看某个文件的修改历史 git log --pretty=oneline 文件名 ...
- git配置多个ssh key
随着工作的深入,我们通常都会有多个git账户.比如公司gitlab一个账户,github或gitee有一个账户.而平时我们又回通过 配置ssh公私钥认证的方式省去繁琐的登录远程仓库的操作,不同的git ...
- PhpStorm Git 配置(解决文件没有变色的问题)
摘要: PhpStorm Git 配置 首先需要安装windows下的Git版本,网上有很多我下载的是msysgit反正都差不多,不会的自己百度. 其次打开PhpStorm,点击File ,Setti ...
- Android开发之Git配置
Android开发之Git配置 1.首先git配置: 输入命令: git config --global user.name "xxx.xx" git config --globa ...
随机推荐
- dubbo(四)
前言 1.浅谈架构的发展 首先,要了解dubbo,就得了解,它是在什么背景下产生的?这就需要从架构的发展说起. 孟老师从事软件开发2008年份,那时候我上高一,那个时候,淘宝.京东都还没有火起来.那个 ...
- 虚拟机安装的kali操作系统实现共享文件夹
虚拟机共享文件夹设置. 1.[虚拟机]-->[设置] 2.先在本地新建一个共享文件夹,然后将此文件夹的路径添加到虚拟机 3.进入kali操作系统,运行命令sudo vmhgfs-fuse .ho ...
- Flask db init 抛出KeyError: 'migrate’这个问题
问题 目录下执行flask db init 结果 抛出KeyError: 'migrate'这个问题 ## 原因 初始化Migrate对象时没有加db 解决: appfactory.py import ...
- Python3.9安装PySpider步骤及问题解决
先写一些前言吧,自己感觉python已经有一定的基础了,但是在安装这个过程居然用了一下午,感觉有些收货,特地写下来与大家分享一下. PySpider是一个强大的网络爬虫系统,GitHub地址:http ...
- 构建后端第3篇之---springb @Alias注解使用
write by 张艳涛 in 202210210,after today i will write aritles by english,because english is so diffent ...
- WCF简单Demo
WCF,光看书的原理,稍微有点枯燥,通过自己动手,会更容易理解契约声明,面向服务,分布式等概念. 1.创建WCF服务. 2.WcfService1.CS中声明新的契约. namespace WcfSe ...
- Pytorch Torchvision Transform
Torchvision.Transforms Transforms包含常用图像转换操作.可以使用Compose将它们链接在一起. 此外,还有torchvision.transforms.functio ...
- 关于Asp.Net MVC html.renderaction传递参数
View视图 @{html.renderaction("控制器方法名","控制器名称",new{params1="参数值"})} Contr ...
- openssl not found 离线安装的openssl问题
离线安装问题 正常我们在Linux中按照 nginx的openssl依赖都是通过 yum来安装的,但是由于一些特殊的服务器公司不让服务器连接互联网,所以就导致我们必须通过离线方式来进行安装,但是我们离 ...
- 【数据结构与算法】字符串匹配(Rabin-Karp 算法和KMP 算法)
Rabin-Karp 算法 概念 用于在 一个字符串 中查找 另外一个字符串 出现的位置. 与暴力法不同,基本原理就是比较字符串的 哈希码 ( HashCode ) , 快速的确定子字符串是否等于被查 ...