本地同時配置github 和gitee 遠程倉庫
在當下,gitee 也成為國內很多開發人員交友社區。同時為了跟上時代的步伐,大家也不想放棄github。所以同時將自己的項目提交到gitee 和github 成了開發人員的訴求。
git 全局用戶設置
## 產看 全局配置
git config --global --list
# 清除(如果未添加過,則不需要清除)
git config --global --unset user.name "name"
git config --global --unset user.email "@mail"
git config --global user.name "new name"
git config --global user.email "new emial"
# 注:--global 表示全局屬性,所有的git項目都會共用屬性。設置本地機器默認commit的昵稱與Email. 必須使用在 gitee 或者 github 上配置的 email.
生成生成新的 SSH keys
GitHub 的鑰匙
# 第一步
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "郵箱1"
out:
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
# 說明: 遇到以上Enter passphrase (empty for no passphrase),直接敲回車即可,不需要輸入用戶名或者密碼
# 第二步
一直敲回車
our identification has been saved in /Users/likun/.ssh/id_rsa.github.
Your public key has been saved in /Users/likun/.ssh/id_rsa.github.pub.
The key fingerprint is:
SHA256:xxxx xxxx
The key's randomart image is:
---[RSA 3072]----+
| xx . xxxx |
+----[SHA256]-----+
Gitee 的鑰匙
# 第一步
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "郵箱2"
# 第二步
一直敲回車
Your identification has been saved in /Users/likun/.ssh/id_rsa.gitee.
Your public key has been saved in /Users/likun/.ssh/id_rsa.gitee.pub.
The key fingerprint is:
SHA256:dFuVYB3D7tIzMbioTmv1O5O1Jl4F8TLIpFqgk0RsHuo 1363653611@qq.com
The key's randomart image is:
+---[RSA 3072]----+
| xx . xxxx |
+----[SHA256]-----+
完成后會在~/.ssh / 目錄下生成以下文件。
- id_rsa.github
- id_rsa.github.pub
- id_rsa.gitee
- id_rsa.gitee.pub
識別 SSH keys 新的私鑰
默認只讀取 id_rsa,為了讓 SSH 識別新的私鑰,需要將新的私鑰加入到 SSH agent 中。改操作可以不執行,不設置也可以成功。
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee
多賬號配置 config 文件
創建config文件
touch ~/.ssh/config
config 中填入如下內容
#Default gitHub user Self
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
# gitee
Host gitee.com
Port 22
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
添加 ssh
分別添加SSH到Gitee和Github:
-
Github:
https://github.com/settings/keys
將 id_rsa.github.pub 中的內容填進去,起名的話隨意。 -
Gitee:
https://gitee.com/profile/sshkeys
將 id_rsa.gitee.pub 中的內容填進去,起名的話隨意。
測試成功
ssh -T git@gitee.com
Hi zbcn! You've successfully authenticated, but GITEE.COM does not provide shell access.
ssh -T git@github.com
Hi 1363653611! You've successfully authenticated, but GitHub does not provide shell access.
IDEA中同時push項目到gitee和github
- 找到 git 的遠程配置

- 多個push項目的時候就可以切換我們想要push的地方

解決本地庫同時關聯GitHub和Gitee
跳轉到要添加關聯遠程倉庫的項目下
我們在本地庫上使用命令git remote add把它同時和Github、Gitee的遠程庫關聯起來
git remote add github git@github.com:xxx/xxx_test.git
git remote add gitee git@gitee.com:xxxx/xx-test.git
此處可以為https地址也可以是ssh地址,orign為設置的遠程倉庫的別名(如果我們關聯兩個的話,則需要設置不同名,比如github和gitee),強烈建議使用ssh方式,因為https方式每次都要輸入用戶名和密碼
- 關聯完成后,我們可以通過輸入
git remote -v來查看關聯的遠程庫信息
這樣一來,我們的本地庫就可以同時與多個遠程庫互相同步:
如果要推送到GitHub,使用命令:git push github master
如果要推送到Gitee,使用命令:git push gitee master

浙公網安備 33010602011771號