同一台机子上用多个git 账号
Step 1 - Create a New SSH Key
We need to generate a unique SSH key for our second GitHub account.
1
|
ssh -keygen -t rsa -C "your-email-address" |
Be careful that you don't over-write your existing key for your personal account. Instead, when prompted, save the file as id_rsa_COMPANY
. In my case, I've saved the file to~/.ssh/id_rsa_nettuts
.
Step 2 - Attach the New Key
Next, login to your second GitHub account, browse to "Account Overview," and attach the new key, within the "SSH Public Keys" section. To retrieve the value of the key that you just created, return to the Terminal, and type: vim ~/.ssh/id_rsa_COMPANY.pub
. Copy the entire string that is displayed, and paste this into the GitHub textarea. Feel free to give it any title you wish.
Next, because we saved our key with a unique name, we need to tell SSH about it. Within the Terminal, type: ssh-add ~/.ssh/id_rsa_COMPANY
. If successful, you'll see a response of "Identity Added."
Step 3 - Create a Config File
We've done the bulk of the workload; but now we need a way to specify when we wish to push to our personal account, and when we should instead push to our company account. To do so, let's create a config
file.
1
2
|
touch ~/. ssh /config vim config |
If you're not comfortable with Vim, feel free to open it within any editor of your choice. Paste in the following snippet.
1
2
3
4
5
|
#Default GitHub Host github.com HostName github.com User git IdentityFile ~/. ssh /id_rsa |
This is the default setup for pushing to our personal GitHub account. Notice that we're able to attach an identity file to the host. Let's add another one for the company account. Directly below the code above, add:
1
2
3
4
|
Host github-COMPANY HostName github.com User git IdentityFile ~/. ssh /id_rsa_COMPANY |
This time, rather than setting the host to github.com
, we've named it as github-COMPANY
. The difference is that we're now attaching the new identity file that we created previously: id_rsa_COMPANY
. Save the page and exit!
Step 4 - Try it Out
It's time to see if our efforts were successful. Create a test directory, initialize git, and create your first commit.
1
2
|
git init git commit -am "first commit' |
Login to your company account, create a new repository, give it a name of "Test," and then return to the Terminal and push your git repo to GitHub.
1
2
|
git remote add origin git@github-COMPANY:Company /testing .git git push origin master |
Note that, this time, rather than pushing to git@github.com
, we're using the custom host that we create in the
config file: git@github-COMPANY
.
Return to GitHub, and you should now see your repository. Remember:
- When pushing to your personal account, proceed as you always have.
- For your company account, make sure that you use
git!github-COMPANY
as the host.
Be sure to refer to the screencast if you need a more visual overview of the steps above!
同一台机子上用多个git 账号的更多相关文章
- linux同一台机子上用多个git 账号
Step 1 - Create a New SSH KeyWe need to generate a unique SSH key for our second GitHub account. ssh ...
- 【git】一台机器上使用不同的git账号
1.生成一个新的自定义名称的公钥: ssh-keygen -t rsa -C "shangxiaofei3@163.com" -f ~/.ssh/sxfself 一直点击回车 执行 ...
- windows系统一台电脑先后添加多个git账号
概述 电脑上已经配置了github的ssh连接.现在又有一个不同的git账户,也就是要在一台电脑上配置两个git账号. 下面记录一下我配置的方法. 一.取消git全局配置 之前配置github的时候, ...
- git学习笔记:一台电脑上配置两个git账户
如何在一台电脑上配置两个git账户,现在云端仓库很多,有开源中国的 gitee.com 微软的 github.com 还有 gitlab.com 和 bitbucket.org 等等,下面是具体步骤 ...
- 简易搭建git仓库、关联远程和本地仓库方法。克隆仓库方法。同一台电脑上创建两个git ssh key方法。
一,在github上建仓库 react-js-antd-demo: 二:将远程仓库与本地仓库关联 git remote add origin git@github.com:begin256/react ...
- SQL2000,2005,2008安装在一台机子上
工欲善其事,必先利其器.本机的系统是在网上自己下载的,是32位windows7旗舰版.因为学习,需要在一台机子上同时安装SQL Server2000,2005,2008三个版本的数据库.先是在网上查了 ...
- Git 在同一台机器上配置多个Git帐号
在同一台机器上配置多个Git帐号 By:授客 QQ:1033553122 实践环境 win10 Git-2.21.0-64-bit.exe TortoiseGit-2.8.0.0-64bit.msi ...
- 一台电脑上配置多个git的ssh key
前几天公司的代码库全部迁移到了阿里云上,在配置git的ssh key的时候遇到了一个问题,那就是自己的密钥在添加时提示已经存在,原来是自己的个人账号上已经添加过这个密钥了,公司分配的账号就不能再添加这 ...
- 四步实现在一台电脑上使用多个github账号
四步实现在一台电脑上同时使用多个GitHub账号 今天和大家聊一下如何在一台电脑上同时使用多个GitHub账号,通过以下四个步骤就可以实现,其中第二个步骤为了便于叙述分成了几个小步骤. 1. 取消全局 ...
随机推荐
- [转]eclipse重新编译
Eclipse打开时并不重新生成class文件,这就造成了eclipse找不到需要的class文件从而不能正常编译工程中的其他代码.此时就需要重新编译工程. 单击Project菜单,选择Clean菜单 ...
- 面试题目——《CC150》排序与查找
面试题11.1:给定两个排序后的数组A和B,其中A的末端有足够的缓冲空间容纳B.编写一个方法,将B合并入A并排序. package cc150.sort_search; public class Me ...
- IK分词器 整合solr4.7 含同义词、切分词、停止词
转载请注明出处! IK分词器如果配置成 <fieldType name="text_ik" class="solr.TextField"> < ...
- sqlserver 自增ID插入指定数据
set identity_insert 表名 ON --允许对自增列Id插入指定数据 insert into table_name(Id,Name) values(1,'test') set iden ...
- 基于浏览器的HTML5地理定位
基于浏览器的HTML5地理定位 地理位置(Geolocation)是 HTML5 的重要特性之一,提供了确定用户位置的功能,借助这个特性能够开发基于位置信息的应用.今天这篇文章向大家介绍一下 HTML ...
- DAY5 DVWA之SQL注入演练(low)
1.设置 把安全等级先调整为low,让自己获得点信心,免得一来就被打脸. 2.测试和分析页面的功能 这里有一个输入框 根据上面的提示,输入用户的id.然后我们输入之后,发现它返回了关于这个 ...
- 逻辑思维面试题-java后端面试-遁地龙卷风
(-1)写在前面 最近参加了一次面试,对笔试题很感兴趣,就回来百度一下.通过对这些题目的思考让我想起了建模中的关联,感觉这些题如果没接触就是从0到1,考验逻辑思维的话从1到100会更好,并且编程简易模 ...
- Jenkins的使用
参考: http://www.cnblogs.com/sunzhenchao/archive/2013/01/30/2883289.html
- xampp本地配置多域名
xampp内建apache服务器,也是可以配置vhosts的 1. 打开httpd.conf文件,搜索vhosts 发现这句话: # Virtual hosts Include conf/extra/ ...
- JQuery 自动触发事件
JQuery 常用模拟 有时候,需要通过模拟用户操作,来达到单击的效果.例如在用户进入页面后,就触发click事件,而不需要用户去主动单击. 在JQuery中,可以使用trigger()方法完成模拟操 ...