如何設定git在不同repository使用不同的身份(user identity) ?
設定全域級別的git身份
一般在Google上找尋設定使用者名稱及電子郵件的方法如下:
git config --global user.name "Roger Li"
git config --global user.email rogerli@xxx.com
那麼如果我電腦上有不同的git repository,可能是個人的project,可能是不同公司的專案,有需要各自設定不同的稱呼和電郵地址,應如何處理呢?
使用git config --global去設定,會把資料記錄在作業系統的個人home profile文件夾內:
- Windows: %userprofile%\.gitconfig
- Linux: ~/.gitconfig
設定專案級別的git身份 (user identity)
只要你先進入到需要設定資料的repos,然後以 --local 去取代 --global 便可。
git config --local user.name "Roger Li"
git config --local user.email rogerli@yyy.com
它便會在repos內的.git文件夾內的config file加入了以下資料:
[user]
name = Roger Li
email = rogerli@yyy.com