1. 爲何會用多個git帳號? html
2. 不一樣git帳號對應不一樣代碼託管平臺,以github和bitbucket爲例 git
1)假設你已經生成了不一樣的 sshkey,其中針對不一樣的平臺能夠命名以下:github
2)個人移動到 /c/Users/xxx/.ssh/目錄下,在該目錄下手動建立文件「config」(無後綴名),編輯config文件,以下:segmentfault
# github account [github_user] Host github.com HostName github.com User github_user IdentityFile /c/Users/xxx/.ssh/id_github_rsa IdentitiesOnly yes # bitbucket account [bct_user] Host bitbucket.org HostName bitbucket.org User btc_user IdentityFile /c/Users/xxx/.ssh/id_bitbucket_rsa IdentitiesOnly yes
3)經過上述配置後,你就可使用多個git帳號操做對應的代碼託管平臺(假設你使用同一個email註冊不一樣的平臺,不然的話,須要取消全局email和username設置,而且在使用前經過git config命令切換帳號,具體請看 3. 同一個平臺GitHub下的不一樣git帳號)bash
3. 同一個平臺(GitHub爲例)下的不一樣git帳號session
1)config 配置以下:ssh
# github account [user1] Host github.com HostName github.com User user1 IdentityFile /c/Users/xxx/.ssh/id_user1_rsa IdentitiesOnly yes # github account [user2] Host github.com HostName github.com User user2 IdentityFile /c/Users/xxx/.ssh/id_user2_rsa IdentitiesOnly yes
2)在使用時須要注意,不能設置全局的 username 和 emailgitlab
# 取消全局 username, email >git config --global --unset user.name >git config --global --unset user.email
3)如要在repo中使用 user1 進行操做,進入repo目錄後,先設置username 和 email,再進行其餘操做測試
>git config user.name "user1" >git config user.email "user1登錄GitHub的email"
# 一樣的,若是想在repo中切換爲 user2 進行操做,則從新設置username和email(同上)後,再進行其餘操做
4. 可能遇到的問題spa
1)git push:remote: Permission to XXXA/xxxx.git denied to XXXB
緣由:
解決方法:
5. 參考內容
轉載請說明出處!have a good time :D