git配置多用户多平台
2017-02-09 14:08
302 查看
在Git使用中经常会碰到多用户问题,例如:你在公司里有一个git账户,在github上有一个账户,并且你想在一台电脑上同时对这两个git账户进行操作,此时就需要进行git多用户配置。
首先配置不同的SSH KEY,使用ssh-keygen命令产生两个不同的SSH KEY,进入.ssh目录:
同理,配置自己的github账户,再有其他账户类似:
在生成ssh key之后,需要分别在github的profile中和公司git的profile中编辑SSH KEY,以github为例:
然后在.ssh目录下配置config文件:
测试配置是否成功
提交代码
本地如果没有项目,git上创建项目仓库并拉取:
本地已有项目,git上创建仓库并拉取
首先配置不同的SSH KEY,使用ssh-keygen命令产生两个不同的SSH KEY,进入.ssh目录:
#切换到.ssh目录 cd ~/.ssh #使用自己的企业邮箱产生SSH KEY ssh-keygen -t rsa -C "mywork@email.com" #企业的可以使用id_rsa,也可以自己起名,例如:id_rsa_work Enter file in which to save the key (/root/.ssh/id_rsa): id_rsa #将ssh key添加到SSH agent中,该命令如果报错:Could not open a connection to your authentication agent.无法连接到ssh agent,可执行ssh-agent bash命令后再执行ssh-add命令。 ssh-add ~/.ssh/id_rsa
同理,配置自己的github账户,再有其他账户类似:
#切换到.ssh目录 cd ~/.ssh #使用自己github的注册邮箱产生SSH KEY ssh-keygen -t rsa -C "mygithub@email.com" #github的SSH KEY Enter file in which to save the key (/root/.ssh/id_rsa): id_rsa_github #将ssh key添加到SSH agent中 ,该命令如果报错:Could not open a connection to your authentication agent.无法连接到ssh agent,可执行ssh-agent bash命令后再执行ssh-add命令。 ssh-add ~/.ssh/id_rsa_github
在生成ssh key之后,需要分别在github的profile中和公司git的profile中编辑SSH KEY,以github为例:
1. Title,可以随便写: 2. 将.ssh目录下对应的id_rsa_github.pub中的内容拷到Key中,点击Add SSH key按钮即可。公司的git类似。
然后在.ssh目录下配置config文件:
#切换到.ssh目录 cd ~/.ssh #创建并编辑config文件 vim config # 粘贴到config文件中 #公司的git地址 Host git.***.com User git Hostname git.***.com #公司的git地址 IdentityFile ~/.ssh/id_rsa #访问公司git的SSH KEY Port *** #公司的git端口 Host github.com User git Hostname github.com #github的地址 IdentityFile ~/.ssh/id_rsa_github #访问github的SSH KEY
测试配置是否成功
#github的地址 ssh -T git@github.com #出现如下内容,表示成功链接github,***为你的github账户的用户名 Hi ***! You've successfully authenticated, but GitHub does not provide shell access. #公司的git地址 ssh -T git@git.***.com #出现如下内容,表示成功链接github,***为公司git账户的用户名 Hi ***! You've successfully authenticated, but GitHub does not provide shell access.
提交代码
本地如果没有项目,git上创建项目仓库并拉取:
git clone git@***:***/git-test.git cd git-test touch README.md git add README.md git commit -m "add README" git push -u origin master
本地已有项目,git上创建仓库并拉取
cd 已有项目目录 git init git remote add origin git@***:***/git-test.git git add . git commit git push -u origin master
相关文章推荐
- JAVA并发线程池,线程锁知识总结
- java动态代理记录
- Java--Mac下终端运行.java文件需要class、interface或enum
- Wireshark网络抓包(四)——工具
- C++单例模式真的简单吗?
- Android插件化系列第(一)篇---Hook技术之Activity的启动过程的拦截
- [NOIPOI2017]2.6日常训练解题报告
- [Android新手学习笔记09]-活动Activity启动模式
- Java中的多线程你只要看这一篇就够了
- Rendering views on the screen
- JS中的上下文this
- 利用百度tts 实现文字转语音(node)
- php 图片指定留白叠加缩放
- 将youku的视频放到自己的网站上面播放
- ionic 踩坑记录笔记
- Python---TypeError: '<' not supported between instances of 'str' and 'int'
- 使用kafka-clients api操作Kafka
- 远程服务器返回错误: (401)未经授权的解决办法
- ubuntu10.04可用源
- Java中的ThreadPoolExecutor