每個項目單獨配置 git 用戶


git多賬號登陸問題
 

設置git全局記住密碼:

git config --global credential.helper store

設置git自己項目記住密碼: 

  1.  cd  你的項目路徑  

  2.  git config credential.helper store

設置git全局設置

git config --global user.name "your_name" 
git config --global user.email  "your_email"

需要取消git的全局設置:

git config --global --unset user.name

git config --global --unset user.email

同理  針對每個項目,單獨設置用戶名和郵箱,設置方法如下:

cd ~到項目根路徑

git config user.name "your_name"
git config user.email "your_email"
說白了,也就是進入到你的git項目相對根目錄下,然后執行git config設置記錄

SSH配置(轉的 未測試)

我看了很多中文博客,發現講的都不太清楚,還是在stackoverflow上,找了一個問題解決我的疑惑:http://stackoverflow.com/questions/14689788/multiple-github-accounts-what-values-for-host-in-ssh-config
解決方法總結如下:
(1) 我現在有兩個git項目,使用的用戶名分別是A/B,用的郵箱分別是C/D
(2) 在~/.ssh目錄下,使用 ssh-keygen -C "your_email" -t rsa 生成公私秘鑰,命名分別為 id_rsa_first, id_rsa_second,公鑰的內容需要分別上傳到git項目的服務器上
(3) 在~/.ssh目錄下創建config文件,進行相應配置:
#第一個git項目賬號 Host first HostName test.com #這里需要用真實的項目檢出hostname,為了項目安全,我這里隨意寫的 User A IdentityFile ~/.ssh/id_rsa_first  #第二個git項目賬號 Host second HostName test2.com Port 1334 User B IdentityFile ~/.ssh/id_rsa_second
(4) 新建git項目檢出目錄,我發現很多同學出問題,在於git項目沒有初始化
mkdir project && cd project git init git config user.name "A" git config user.email "C"
相應的第二個項目也參照上面的指令進行初始化設置
(5)檢出服務端項目代碼,這里需要注意,使用.ssh目錄下的host代替真實的hostname,這樣才能讓git識別出來
git remote add first git@first:A/project.git
如果使用的是repo,也是同樣操作
repo init -u ssh://A@first -b branch
(6)push的時候,push到對應的Host即可
first項目中: git push fist master


免責聲明!

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



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