Skip to content

Instantly share code, notes, and snippets.

@jackyu
Last active May 31, 2021 02:36
Show Gist options
  • Save jackyu/b45e3099cefe1a6750050e7b628e8337 to your computer and use it in GitHub Desktop.
Save jackyu/b45e3099cefe1a6750050e7b628e8337 to your computer and use it in GitHub Desktop.
[筆記][Git] 如何在 gitconfig 中指定多個 user

如何在 gitconfig 中使用多組 user 設定

會有這個想法,是因為原始全域設定中,我設定的 user 資訊中,是使用我個人的 GMail 信箱 而隨著各專案的屬性不同,例如: 公司專案,需要使用的就是公司的 Email 但又不想每個專案都再建一份 .gitconfig 設定 於是,可以使用以下方式

在 git 2.13 版後,可以使用判斷條件 Conditional includes 在全域設定 ~/.gitconfig 中指定特定專案目錄下載入指定的 gitconfig

[user]
    name = John Doe
    email = john@doe.tld

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

專案目錄下�~/work/.gitconfig

[user]
    email = john.doe@company.tld

參考

Can I specify multiple users for myself in .gitconfig?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment