git 在一台机器上配置多个账户
前提:
必须知道怎样配置git账户,请參考git官方教程:https://help.github.com/articles/generating-ssh-keys
这个教程能教你怎样生成ssh-key,以及怎样加入ssh-key。
补充一点。怎样设置user.name和user.email。命令例如以下:
1)设置局部的user.name和user.email
git config user.name “xxxxxx”
git config user.email “xxx@xxx.com”
2) 设置全局的user.name和user.email
git config --gloable user.name “xxxxxx”
git config –gloable user.email “”
第一步:
建一个新的github账户。名字为testaccount,假设你已经有了。跳过此步(注:你之前已经有了一个老的账户了,假设没有,请看“前提”先来一个账户)
第二步:
假设自己会生成和配置ssh-key。那么要配其它账户首先要在生成一个ssh-key。当然新的ssh-key名称要和之前的有所差别,默认的private key 名称为id_rsa。新的key要换个名称。比方id_rsa2。这样生成一套key的名称分别为id_rsa2和id_rsa2.pub。而默认的文件为id_rsa和id_rsa.pub
在github上建一个新的repository。当然是基于你的第二个账户testaccount的。比如名称为test
第三步:
git clone下来
第四步:
然后要在.ssh文件夹下配置一下config文件(假设没有,创建它),样例例如以下:
# Default account
Host github.com
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa
# New account
Host github2.com
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa2
此时发现,这个配置看不懂啊,没关系,下边你能够使用命令,在一个test文件夹下运行git config -l 命令查看配置。例如以下所看到的:
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
mergetool.prompt=false
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=git@github.com:testaccount/test.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name= xxxxxx
user.email=xxx@xxx.com
注意这一行remote.origin.url=git@github.com:testaccount/test.git,这里的 github.com表示config文件中的hostname,事实上他并非hostname而是一个别名,这样解释:
git@别名: testaccount/test.git解析的路径为 git@github.com:testaccount/test.git而我配的default account的host和hostname刚好一样,假设仅仅有一个账户的时候,它并不表示别名而是路径。此时我们不须要配置config文件。我们设置config文件的目的是由于我们有两套key,分别用在两个repository,而我们须要分别指向这两个key。简单来说。我们是要通过host来找到key。即通过host映射到IdentityFile。
此时打开test文件夹下.get文件夹(隐藏文件夹)的config文件,内容例如以下:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = git@github.com:testaccount/test.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
name = testaccount
email = xxx@xxx.com
我们仅仅需把 url = git@github.com:testaccount/test.git改为 url = git@github2.com:testaccount/test.git,即使用了new account的host来配置。映射到了新的IdentityFile新的key,就可以保存文件再使用命令git config -l 查看配置例如以下:
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
mergetool.prompt=false
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=git@github2.com:testaccount/test.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name= testaccount
user.email=xxx@xxx.com
大功告成。你能够push代码了
git 在一台机器上配置多个账户的更多相关文章
- Git 在同一台机器上配置多个Git帐号
在同一台机器上配置多个Git帐号 By:授客 QQ:1033553122 实践环境 win10 Git-2.21.0-64-bit.exe TortoiseGit-2.8.0.0-64bit.msi ...
- 【git】一台机器上使用不同的git账号
1.生成一个新的自定义名称的公钥: ssh-keygen -t rsa -C "shangxiaofei3@163.com" -f ~/.ssh/sxfself 一直点击回车 执行 ...
- Hexo博客系列(二)-在多台机器上利用Hexo发布博客
[原文链接]:https://www.tecchen.xyz/blog-hexo-env-02.html 我的个人博客:https://www.tecchen.xyz,博文同步发布到博客园. 由于精力 ...
- git学习笔记:一台电脑上配置两个git账户
如何在一台电脑上配置两个git账户,现在云端仓库很多,有开源中国的 gitee.com 微软的 github.com 还有 gitlab.com 和 bitbucket.org 等等,下面是具体步骤 ...
- 一台电脑上配置多个git的ssh key
前几天公司的代码库全部迁移到了阿里云上,在配置git的ssh key的时候遇到了一个问题,那就是自己的密钥在添加时提示已经存在,原来是自己的个人账号上已经添加过这个密钥了,公司分配的账号就不能再添加这 ...
- git+jenkins在windows机器上新建一个slave节点【转载】
转至博客:上海-悠悠 前言 我们在跑自动化项目的时候,希望有单独的测试机能跑自动化项目,并且能集成到jenkins上构建任务.如果公司已经有jenkins环境了,那无需重新搭建. 只需在现有的平台基础 ...
- 如何在同一台机器上安装多个MySQL的实例
转自:'http://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的 ...
- 如何在同一台机器上安装多个MySQL的实例 转
https://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MyS ...
- 如何在同一台机器上安装多个MySQL的实例(转)
最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MySQL的实例). 先说下,什么是mysql的多实例,简单的来说就是一台机器上安装了多个mysql的服务 ...
随机推荐
- java线程池,信号量使用demo
直接上代码 package org.jimmy.threadtest20181121; import java.util.concurrent.LinkedBlockingQueue; import ...
- intellij idea集成github
IDEA配置github并上传项目 http://www.cnblogs.com/jinjiyese153/p/6796668.html github ssl验证 https://www.cnblog ...
- x264介绍
x264 编辑 H.264是ITU(International Telecommunication Unite 国际通信联盟)和MPEG(Motion Picture Experts Group ...
- 学习 Qt 编程的好书精品推荐!
最近一段时间,准备开始搞Qt方面的东西,想找几本书看看.网上介绍QT的书籍也有很多,不想浪费时间,所以想找几本精品的书籍来看.花了半天的时间找了几本非常不错的,这里面整理好之后推荐给大家! 下面介绍的 ...
- Android Studio + Genymotion模拟器安装与配置
一.Android studio 下载与安装 https://developer.android.google.cn/studio/index.html 进入谷歌官方链接下载Android studi ...
- 详细了解为什么支持Postman Chrome应用程序已被弃用?
本地postman chrome插件确实也无法正常使用,只有Postman官方自己的软件应用程序可以使用.笔者多少追溯终于知道原因,并紧急上线了不同操作系统版本的Postman应用程序. 为什么近期P ...
- selenium切换frame(iframe)
例如网页代码为: <!DOCTYPE html><html lang="en"><head> <meta charset="UT ...
- Spider-Python爬虫之聚焦爬虫与通用爬虫的区别
为什么要学习爬虫? 学习爬虫,可以私人订制一个搜索引擎. 大数据时代,要进行数据分析,首先要有数据源. 对于很多SEO从业者来说,从而可以更好地进行搜索引擎优化. 什么是网络爬虫? 模拟客户端发送网络 ...
- 04001_HTML简单介绍
1.超文本标记语言 (1)超文本:比普通文本功能更加强大: (2)标记语言:使用一组标签对内容进行描述的一门语言,它不是编程语言! 2.HTML语法和规范 (1)所有的html文件后缀名都是以.htm ...
- maven运行tomcat6出现错误Exception starting filter encodingFilter怎么解决
严重: Exception starting filter encodingFilterjava.lang.ClassCastException: org.springframework.web.fi ...