Window环境下使用多个Git账号(github,gitee,gitlab,gogs等)
<p> 个人电脑之前已经设置好github账号了,公司用的是gitlab私服,一直互不干扰,因为用的是不同的电脑,也就懒得配置git多账户环境。最近看了一下多年空空如也的码云,想着怎么的也会用到gitee来托管代码的吧,那么现在就来把git环境准备一下吧,先。</p><h3>生成githee密钥</h3>
<p> 在桌面右键git bash here,执行命令<strong>ssh-keygen -t rsa -C email </strong>为gitee创建sshkey,我的电脑已经配置好github账号的,之前没有取别名,默认就是id_rsa,所以enter file这行给gitee密钥取个别名id_rsa_gitee,需不需要密码,看自己需求,我是没有设置密码的,所以enter passphrase这行直接回车了。回车确认后会在桌面创建两个文件,id_rsa_gitee和id_rsa_gitee.pub。</p>
<p><img src="https://img2018.cnblogs.com/blog/1089433/201910/1089433-20191008220519979-1256213360.jpg" alt=""></p>
<p> </p>
<h3>账号关联</h3>
<p> 将这两个文件移动到用户名下的.ssh目录下,复制id_rsa_gitee.pub里面的内容,在码云新增一个ssh公钥。</p>
<p><img src="https://img2018.cnblogs.com/blog/1089433/201910/1089433-20191008221546043-1650219660.jpg" alt=""></p>
<p> </p>
<h3>多账号git配置</h3>
<p> 在.ssh目录下新增一个config文件,我是创建了一个config.txt文本文件,然后将后缀去掉。用编辑器来创建这个文件也是一样的。如果github和gitee账号不一样的话,配置不同的账号也是支持的。config内容如下:</p>
<div class="cnblogs_code"><img id="code_img_closed_a55b630f-7016-46a1-b940-bbc515f8d9a6" class="code_img_closed" src="https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif" alt=""><img id="code_img_opened_a55b630f-7016-46a1-b940-bbc515f8d9a6" class="code_img_opened" style="display: none" src="https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif" alt="">
<div id="cnblogs_code_open_a55b630f-7016-46a1-b940-bbc515f8d9a6" class="cnblogs_code_hide">
<pre><span style="color: rgba(0, 0, 0, 1)"># github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile </span>~/.ssh/<span style="color: rgba(0, 0, 0, 1)">id_rsa
User your_github_account
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile </span>~/.ssh/<span style="color: rgba(0, 0, 0, 1)">id_rsa_gitee
User your_gitee_account</span></pre>
</div>
<span class="cnblogs_code_collapse">View Code</span></div>
<p> </p>
<h3>git账号测试</h3>
<p> 在git bash输入命令 <strong>ssh -T git@gitee.com</strong>,出现欢迎信息,配置成功。</p>
<p><img src="https://img2018.cnblogs.com/blog/1089433/201910/1089433-20191008223215018-1389698609.jpg" alt=""></p>
<p> </p>
<h3>git clone&push</h3>
<p> 在gitee创建一个仓库,随便创建了一个之前在网络下载的前端效果,应该是没有版权的,如有侵权,请联系:)</p>
<p><img src="https://img2018.cnblogs.com/blog/1089433/201910/1089433-20191008225501337-1174325768.jpg" alt=""></p>
<p> 使用ssh方式clone仓库到本地。</p>
<p><img src="https://img2018.cnblogs.com/blog/1089433/201910/1089433-20191008230228307-1878414082.jpg" alt=""></p>
<p> 添加文件,commit,push,成功推送到gitee远程仓库。</p>
<p><img src="https://img2018.cnblogs.com/blog/1089433/201910/1089433-20191008234409118-178766368.jpg" alt=""></p>
<p> </p>
<p> github之前就有用过,就不再试验了。使用gitlab或者gogs搭建的git私服配置同理。</p>
<p> </p><br><br>
来源:https://www.cnblogs.com/fallTakeMan/p/11638726.html
頁:
[1]