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的服务 ...
随机推荐
- 基于ant design form的二次封装
// standardForm.js import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; ...
- webdrive脚本打开firefox浏览器,报“AttributeError: module 'selenium.webdriver' has no attribu
按照网上提供的方法: 下载geckodriver之后解压缩到 Firefox安装目录 下 添加 Firefox安装目录 到 系统变量Path 重启pycharm 照此步骤执行后,仍然报同样的错.折腾了 ...
- js中事件冒泡和事件捕获
什么时候存在这种问题? 当一个行为触发了多个对象的事件时. <body> <div class="fa"> <div class=&q ...
- 五段实用的js高级技巧
技巧一之setTimeout. 应用案例:比如你想一个函数循环执行10次,怎么办?以前通常是先setInterval,然后clearInterval,技巧一就是克服这个问题 复制代码 代码如下: (f ...
- 8.url路由
1.单一路由对应 url(r'^index/$', views.index), 这里要注意的是,/$ 表示只有只/结尾的才有效,如果把$符号去掉的话,只要是以index/开头都会匹配到这个url. 2 ...
- CUDA_one
首先我看了讲解CUDA基础部分以后,大致对CUDA的基本了解如下: 第一:CUDA实行并行化的过程分为两部分,一个是线程块之间的并行(这是在每个线程网格中grid进行的),一个是对于每一个线程块内部各 ...
- xcap发包工具的简单使用1(构造报文)
xcap是一个免费的网络发包工具,可以构造和发送常用的网络报文,如arp,ip,icmp,udp等,支持构造报文和发送报文等. 报文隶属于报文组,每个报文组包含多个报文,因此,创建报文首先要创建报文组 ...
- 九度oj 题目1202:排序
题目1202:排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:28802 解决:9408 题目描述: 对输入的n个数进行排序并输出. 输入: 输入的第一行包括一个整数n(1<=n ...
- 九度oj 题目1063:整数和
题目1063:整数和 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4043 解决:2638 题目描述: 编写程序,读入一个整数N.若N为非负数,则计算N到2N之间的整数和:若N为一个负数 ...
- LaTex/Overleaf使用笔记
1. 添加网页引用 @misc{ r1, author = "Wikipedia", title = "Binary decision diagram --- { ...