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的服务 ...
随机推荐
- Ubuntu下systemd服务的配置
1. 在/lib/systemd/system目录下创建服务启动脚本testservice.service 2. 文件内容如下: [Unit] Description=TestService [Ser ...
- H5实现调用本地摄像头实现实时视频以及拍照功能
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- JS如何禁用浏览器的退格键
<script type="text/javascript"> //处理键盘事件 禁止后退键(Backspace)密码或单行.多行文本框除外 function forb ...
- CentOS7-wget命令
Wget主要用于下载文件,在安装软件时会经常用到,以下对wget做简单说明.转载自:https://www.cnblogs.com/lxz88/p/6278268.html 1.下载单个文件:wget ...
- Bootstrap 12 栅格系统
栅格系统简介 Bootstrap 提供了一套响应式.移动设备优先的流式栅格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多 12 列.它包含了易于使用的预定义类,还有强大的mix ...
- mysql 删除数据重复的记录
delete from user where id not in ( select * from ( select min(id) from user group by username,email ...
- LeetCode(50) Pow(x,n)
题目 Implement pow(x, n). Show Tags Show Similar Problems 分析 一个不利用标准幂次函数的,求幂算法实现. 参考了一个很好的解析博客:Pow(x,n ...
- 如何设置路由器的MTU
前几天搞了个ER-X,总觉得没有发挥其最大的能力.今天查了下如何设置MTU,罗列如下,备忘. 1. 目前都是PPPOE,这个不管网络如何复杂,均不要在路由后面计算封包大小.正确的是电脑直接连猫,直接拔 ...
- FPGA学习笔记(六)—— 时序逻辑电路设计
用always@(posedge clk)描述 时序逻辑电路的基础——计数器(在每个时钟的上升沿递增1) 例1.四位计数器(同步使能.异步复位) // Module Name: coun ...
- UVALive 6507 Passwords
Passwords Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...