gitconfig์ conditional includes๋ฅผ ์ฌ์ฉํ๋ฉด ๋ก์ปฌ ์ปดํจํฐ์ ๋๋ ํ ๋ฆฌ๋ณ๋ก gitconfig ์ ๊ด๋ฆฌํ๋ ๊ฒ์ด ๊ฐ๋ฅํ๋ค.
๋ค์๊ณผ ๊ฐ์ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค๊ณ ๊ฐ์ ํด๋ณด์.
working-directory โโโ company # ํ์ฌ ํ๋ก์ ํธ โโโ github # ๊ฐ์ธ ํ๋ก์ ํธํ์ฌ ํ๋ก์ ํธ์์๋ ํ์ฌ ๋ฉ์ผ์ธ me@company.com ๋ฅผ git user.email๋ก ์ฌ์ฉํ๋ ค๊ณ ํ๊ณ , ๊ฐ์ธ ํ๋ก์ ํธ์๋ me@gmail.com ์ git user.email๋ก ์ฌ์ฉํ๊ณ ์ถ๋ค๊ณ ํ์.
์ ์ญ ์ค์ ์ผ๋ก๋ ๊ฐ์ธ ๊ณ์ ์ ์ค์ ํ๋ค.
git config --global user.name megit config --global user.email me@gmail.com๊ทธ๋ฆฌ๊ณ ~/.gitconfig ์ ์ด์ด์ user ์น์
์๋์ includeIf ์น์
์ ์ถ๊ฐํ๋ค.
.gitconfig
[user] name = me email = me@gmail.com
[includeIf "gitdir:~/working-directory/company/"] path = ~/working-directory/company/company.incgitdir: ์ glob ํจํด์ ๋ฐ๋ฅด๋ ๋ฌธ์์ด๋ก, git directory ๊ฐ ํด๋น ํจํด๊ณผ ์ผ์นํ๋ฉด, path์ ์๋ ํ์ผ์ include ํ๋ค.
gitconfig ํ์ผ์ ์๋์ ์ค์ ์ด ์์ ์ค์ ์ ๋ฎ์ด์ฐ๊ธฐ ๋๋ฌธ์ ํด๋น ๊ฒฝ๋ก์ ํ์ผ์ user ์ค์ ์ ํด๋๋ฉด, user ์ค์ ์ด ๋ฎ์ด์ฐ์ฌ ํด๋น ์ค์ ์ ์ฌ์ฉํ๊ฒ ๋๋ค.
~/working-directory/company/company.inc
[user] email = me@company.com์ด๋ ๊ฒ ์ค์ ํ ๋ค์ ~/working-directory/company/ ํ์์ ์๋ก์ด git ๋ ํฌ์งํ ๋ฆฌ๋ฅผ์์ฑํ๋ฉด, git ์ด๋ฉ์ผ์ด ํ์ฌ ๊ณ์ ์ธ ๊ฒ์ ํ์ธํ ์ ์๋ค.

์ ์ํ ์ ์ git์ด ์ค์ ๋ ๋ ํฌ์งํ ๋ฆฌ์ด์ผ ํ๋ค๋ ๊ฒ์ด๋ค.