<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Aaron Ji's blog (Posts about git)</title><link>https://blog.jiya.net/</link><description></description><atom:link href="https://blog.jiya.net/categories/git.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2025 &lt;a href="mailto:me@jiya.net"&gt;Aaron Ji&lt;/a&gt; </copyright><lastBuildDate>Wed, 19 Feb 2025 06:17:18 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Git的多账号如何处理？</title><link>https://blog.jiya.net/posts/2015/03/git-multi-account.html</link><dc:creator>Aaron Ji</dc:creator><description>&lt;div id="outline-container-org1d1a051" class="outline-2"&gt;
&lt;h2 id="org1d1a051"&gt;同一台电脑可以有2个git账号（不同网站的）&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-org1d1a051"&gt;
&lt;p&gt;
首先不同网站，当然可以使用同一个邮箱，比如我的 github，gitlab，bitbucket 的账号都是 &lt;code&gt;monkeysuzie[at]gmail.com&lt;/code&gt; 这时候不用担心密钥的问题，因为这些网站 &lt;code&gt;push pull&lt;/code&gt; 认证的唯一性的是邮箱比如我的 &lt;code&gt;windows&lt;/code&gt; 上 2个账号一个 &lt;code&gt;gitlab&lt;/code&gt; 一个 &lt;code&gt;github&lt;/code&gt; （用的都是 &lt;code&gt;id_rsa&lt;/code&gt; ）
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;host github
  hostname github.com
  Port 22
host gitlab.zjut.com
  hostname gitlab.zjut.com
  Port 65095
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;
不需要指定key的位置。因为默认读取 &lt;code&gt;id_rsa&lt;/code&gt; 了
&lt;/p&gt;

&lt;p&gt;
这样子使用起来没有任何区别， &lt;code&gt;remote&lt;/code&gt; 也想平时一样操作即可。因为邮箱是相同的。
&lt;/p&gt;

&lt;p&gt;
同一台电脑有2个 &lt;code&gt;github&lt;/code&gt; 账号？咋办
&lt;/p&gt;

&lt;p&gt;
比如我服务器上模拟的2个用户
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;#monkeysuzie@gmail.com   我在gitlab的第一个账号suzie
host gitlab.zjut.com
    hostname gitlab.zjut.com
    Port 65095
    User suzie
    IdentityFile /home/suzie/.ssh/id_rsa
#  我在gitlab的第2个账号test
host gitlab-test.zjut.com
    hostname gitlab.zjut.com
    Port 65095
    User test
    IdentityFile /home/suzie/.ssh/id_rsa_second
#837368104@qq.com 我在github的账号
host github-osteach.com
    hostname github.com
    Port 22
    User osteach
    IdentityFile /home/suzie/.ssh/id_rsa_second
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;
这种情况下，需要几点注意
&lt;/p&gt;

&lt;ul class="org-ul"&gt;
&lt;li&gt;remote pull push的时候有问题，因为要设置邮箱问题了&lt;/li&gt;
&lt;li&gt;pull的时候识别的是邮箱，2个github账号，2个邮箱，我们自然不能使用global的user.email了&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;1.取消global
git config --global --unset user.name
git config --global --unset user.email

2.设置每个项目repo的自己的user.email
git config  user.email "xxxx@xx.com"
git config  user.name "suzie"
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;
之后push pull就木有问题了
&lt;/p&gt;

&lt;p&gt;
备注：
&lt;/p&gt;

&lt;p&gt;
生成 &lt;code&gt;ssh key&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;ssh-keygen -m rsa -C "your mail"&lt;/code&gt; （当前目录）
然后可以命名默认 &lt;code&gt;id_rsa&lt;/code&gt; 或者 &lt;code&gt;id_rsa_second&lt;/code&gt; 把对应的pub放到公共服务器上。
&lt;/p&gt;

&lt;p&gt;
摘自：&lt;a href="https://gist.github.com/suziewong/4378434"&gt;https://gist.github.com/suziewong/4378434&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</description><category>account</category><category>git</category><category>multi</category><guid>https://blog.jiya.net/posts/2015/03/git-multi-account.html</guid><pubDate>Sat, 21 Mar 2015 13:00:00 GMT</pubDate></item><item><title>Git创建新项目</title><link>https://blog.jiya.net/posts/2014/12/git-init-new-repositories.html</link><dc:creator>Aaron Ji</dc:creator><description>&lt;div id="outline-container-orgf376181" class="outline-2"&gt;
&lt;h2 id="orgf376181"&gt;服务端&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-orgf376181"&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ mkdir myproject.git
$ cd myproject.git
$ git init --bare
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-org938220d" class="outline-2"&gt;
&lt;h2 id="org938220d"&gt;本地&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-org938220d"&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ mkdir myproject
$ git init
$ git add *
$ git commit -m 'initial commit'
$ git remote add origin git@example.com:path/to/myproject.git # 为版本库添加名为origin的远程版本库
$ git push -u origin master # 推送
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;
参考：&lt;a href="http://www.worldhello.net/gotgithub/03-project-hosting/010-new-project.html"&gt;http://www.worldhello.net/gotgithub/03-project-hosting/010-new-project.html&lt;/a&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</description><category>git</category><guid>https://blog.jiya.net/posts/2014/12/git-init-new-repositories.html</guid><pubDate>Tue, 23 Dec 2014 13:00:00 GMT</pubDate></item></channel></rss>