git subtree๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์ถ”๊ฐ€๋œ ์„œ๋ธŒ ๋ ˆํฌ๋ฅผ ์ˆ˜์ •ํ•˜๋ ค๋ฉด, ๋ช‡ ๊ฐ€์ง€ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ๋”ฐ๋ผ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ˆ˜์ • ๋ฐฉ๋ฒ•์€ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์ง์ ‘ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜, ์„œ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ํ‘ธ์‹œํ•˜๋Š” ๋ฐฉ์‹์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค.

git subtree ๋ช…๋ น์–ด์—์„œ <sub-repo-url> ๋Œ€์‹  remote๋ฅผ ๋“ฑ๋กํ•˜์—ฌ ๋Œ€์‹  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

git remote add <sub-repo-name> <sub-repo-url>

1. ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์„œ๋ธŒ ๋ ˆํฌ ์ˆ˜์ •

์›Œํฌํ”Œ๋กœ์šฐ

  1. ์ˆ˜์ • ์ž‘์—… ์ˆ˜ํ–‰ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์„œ๋ธŒ ๋ ˆํฌ๊ฐ€ ์œ„์น˜ํ•œ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™ํ•ด ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

    cd <parent-repo>
    nano <subdirectory>/<file-to-edit>
    
  2. ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์ปค๋ฐ‹ ์ˆ˜์ •๋œ ๋‚ด์šฉ์„ ์ปค๋ฐ‹ํ•ฉ๋‹ˆ๋‹ค. ์ด ์ปค๋ฐ‹์€ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ ํžˆ์Šคํ† ๋ฆฌ์— ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค.

    git add <subdirectory>/<file-to-edit>
    git commit -m "Modified file in subtree"
    
  3. ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์„œ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ํ‘ธ์‹œ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์„œ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ํ‘ธ์‹œํ•ฉ๋‹ˆ๋‹ค.

    git subtree push --prefix=<subdirectory> <sub-repo-url> <branch>
    

    ์˜ˆ:

    git subtree push --prefix=project1 <https://github.com/username/project1.git> main
    

2. ์„œ๋ธŒ ๋ ˆํฌ์—์„œ ์ง์ ‘ ์ˆ˜์ • ํ›„ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ๋ฐ˜์˜

์›Œํฌํ”Œ๋กœ์šฐ

  1. ์„œ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ํด๋ก  ์„œ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ณ„๋„๋กœ ํด๋ก ํ•˜์—ฌ ์ˆ˜์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

    git clone <https://github.com/username/project1.git>
    cd project1
    
  2. ์ˆ˜์ • ์ž‘์—… ๋ฐ ํ‘ธ์‹œ ์„œ๋ธŒ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ ํ•„์š”ํ•œ ์ˆ˜์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ปค๋ฐ‹ ๋ฐ ํ‘ธ์‹œํ•ฉ๋‹ˆ๋‹ค.

    nano <file-to-edit>
    git add <file-to-edit>
    git commit -m "Updated file in sub-repo"
    git push origin main
    
  3. ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์„œ๋ธŒ ๋ ˆํฌ ์—…๋ฐ์ดํŠธ ๋ถ€๋ชจ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ์„œ๋ธŒ ๋ ˆํฌ๋ฅผ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

    cd <parent-repo>
    git subtree pull --prefix=<subdirectory> <sub-repo-url> <branch> --squash
    

    ์˜ˆ:

    git subtree pull --prefix=project1 <https://github.com/username/project1.git> main --squash
    

3. ๊ธฐ๋ณธ ์›์น™

๋ณ€๊ฒฝ ์ž‘์—… ์œ„์น˜

ํžˆ์Šคํ† ๋ฆฌ ๊ด€๋ฆฌ