Git submodule

A์— B ์ถ”๊ฐ€

cd <path/A>
git submodule add <URL/B> <path/A/path/B>
git commit -m "Add submodule B"
A
โ”œโ”€โ”€ .git
โ”œโ”€โ”€ .gitmodules
โ””โ”€โ”€ B
โ””โ”€โ”€ .git

Submodule B ์ˆ˜์ •

B ์•ˆ์˜ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์ง„ํ–‰ํ•˜๋ฉด ์ˆ˜์ •ํ•œ ๋‚ด์šฉ์ด B ์ €์žฅ์†Œ์—๋งŒ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

cd <path/A/path/B>
git add <file>
git commit -m <commit message>

A ์ €์žฅ์†Œ์—๋„ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•ฉ๋‹ˆ๋‹ค.

cd <path/A>
git commit -am "Update submodule B"

B ์ˆ˜์ • ํ›„ A์— ์ ์šฉ

B ์ €์žฅ์†Œ์˜ ์—…๋ฐ์ดํŠธ ๋‚ด์šฉ์„ ๋จผ์ € pull ํ•ฉ๋‹ˆ๋‹ค.

cd <path/A/path/B>
git checkout <branch>
git pull

A ์ €์žฅ์†Œ์— ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•ฉ๋‹ˆ๋‹ค.

cd <path/A>
git commit -am "Update submodule B"

Submodule์ด ์žˆ๋Š” ์ €์žฅ์†Œ clone

git clone --recursive <URL/A>

B๋Š” detached ์ƒํƒœ์ž…๋‹ˆ๋‹ค. ์ˆ˜์ •์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ checkout์„ ํ†ตํ•ด ์›ํ•˜๋Š” ๋ธŒ๋žœ์น˜๋กœ ๋ณ€๊ฒฝํ•œ ํ›„ ์ž‘์—…ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

์•„๋ž˜ ๋ช…๋ น์–ด ๊ฒฐ๊ณผ๋Š” git clone --recursive <URL/A>์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.

git clone <URL/A> \
&& git submodule init \
&& git submodule update

Submodule์ด ๋ณ€๊ฒฝ๋œ A pull

cd <path/A>
git pull
git submodule update
Last updated on