๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

Conditional Include๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋””๋ ‰ํ† ๋ฆฌ ๋ณ„ gitconfig ์„ค์ •ํ•˜๊ธฐ

ยท ์•ฝ 2๋ถ„

git-config - conditional includes

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.inc

gitdir: ์€ glob ํŒจํ„ด์„ ๋”ฐ๋ฅด๋Š” ๋ฌธ์ž์—ด๋กœ, git directory ๊ฐ€ ํ•ด๋‹น ํŒจํ„ด๊ณผ ์ผ์น˜ํ•˜๋ฉด, path์— ์žˆ๋Š” ํŒŒ์ผ์„ include ํ•œ๋‹ค.

gitconfig ํŒŒ์ผ์€ ์•„๋ž˜์˜ ์„ค์ •์ด ์œ„์˜ ์„ค์ •์„ ๋ฎ์–ด์“ฐ๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ๊ฒฝ๋กœ์˜ ํŒŒ์ผ์— user ์„ค์ •์„ ํ•ด๋‘๋ฉด, user ์„ค์ •์ด ๋ฎ์–ด์“ฐ์—ฌ ํ•ด๋‹น ์„ค์ •์„ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค.

~/working-directory/company/company.inc

[user]    email = me@company.com

์ด๋ ‡๊ฒŒ ์„ค์ •ํ•œ ๋’ค์— ~/working-directory/company/ ํ•˜์œ„์— ์ƒˆ๋กœ์šด git ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ์ƒ์„ฑํ•˜๋ฉด, git ์ด๋ฉ”์ผ์ด ํšŒ์‚ฌ ๊ณ„์ •์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

conditional-include-gitconfig-example

์œ ์˜ํ•  ์ ์€ git์ด ์„ค์ •๋œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.