windows 下部署多個git賬戶(gitee、github)


1. 清除 git 的全局設置(針對已安裝 git)

新安裝 git 跳過。

若之前對 git 設置過全局的 user.name 和 user.email
類似 (用 git config --global --list 進行查看你是否設置)

$ git config --global user.name
"你的名字" $ git config --global user.email "你的郵箱"

必須刪除該設置

$ git config --global --unset user.name "你的名字"
$ git config --global --unset user.email "你的郵箱"

2. 生成新的 SSH keys

打開git bash 運行

1:先配置github

生成一個github用的SSH-Key密鑰:輸入命令:(id_rsa_github是生成公鑰的名)

在指定的 .ssh 目錄下 運行

  

ssh-keygen -t rsa -C "yourname@email.com"

或者

 

$ ssh-keygen -t rsa -C '你的郵箱' -f ~/.ssh/id_rsa_github

 

 

 

2:配置gitee

生成一個gitee用的SSH-Key密鑰:輸入命令:(id_rsa_gitee是生成公鑰的名)

在指定的 .ssh 目錄下 運行

 

ssh-keygen -t rsa -C "yourname@email.com"

直接回車3下,什么也不要輸入,就是默認沒有密碼。

 

 

3:查看公鑰 添加到對應賬號下的

 命令:

  

cat id_rsa_github.pub

 

 

 

 

3. 配置config文件

需要在.ssh文件夾下新建config文件,先新建config.txt,然后修改文件名去掉后綴。

config文件內容如下:

其中第二行和第三中 需要填寫gitlab的倉庫地址

# gitee1
    Host 1.gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitee
    User 賬號郵箱
# gitee2
    Host 2.gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitee User 賬號郵箱 

# github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
    User 賬號郵箱
————————————————
 

# 配置文件參數
# Host : Host可以看作是一個你要識別的模式,對識別的模式,進行配置對應的的主機名和ssh文件 /每個Host主要配置HostName和IdentityFile即可
# HostName : 要登錄主機的主機名
# User : 登錄名
# IdentityFile : 指明上面User對應的identityFile路徑

 

Host github.com /*服務器地址為github地址*/

User "XXX@XX.com" /*github上的注冊郵箱為用戶賬號*/

Hostname ssh.github.com /*服務器地址為github地址*/

PreferredAuthentications publickey /*采用公匙*/

IdentityFile ~/.ssh/id_rsa /*公匙文件路徑*/

Port 443 /*修改端口為443*/

 

 

4. 測試

 

$ ssh -T git@1.gitee.com
$ ssh -T git@2.gitee.com
$ ssh -T git@github.com


 

 

5,Git配置多用戶和郵箱

Git的用戶信息配置
Git的配置一共有三個級別:system(系統級)、global(用戶級)和local(版本庫)。system的配置整個系統只有一個,global的配置每個賬戶只有一個,local的配置取決於Git版本庫數量,在版本庫才能看到。
從Git官網的資料來看,這三個級別是逐層覆蓋的。首先去查找system配置,其次查找global配置,最后查找local配置。逐層查找的過程中若查到配置值,則會覆蓋上一層的配置。假如三個級別都配置了用戶信息,則最后生效的配置是local(版本庫)級的。

Git配置用戶名郵箱的命令
system配置

git config --system user.name "username"
git config --system user.email user@email.com

global配置

git config --global user.name "username"
git config --global user.email user@email.com

local配置

git config --local user.name "username"
git config --local user.email user@email.com

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM