IT Talks

git subtree - repository ๋‚ด์— ๋‹ค๋ฅธ repository link ํ•˜๊ธฐ

OJJ 2023. 3. 22. 11:09

Github ๋“ฑ์—์„œ git ์„ ํ†ตํ•ด ์ฝ”๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋‹ค ๋ณด๋ฉด ์—ฌ๋Ÿฌ repo ์— ์ค‘๋ณต๋˜๋Š” ์ฝ”๋“œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋Ÿฐ repo ๊ฐ„ ์ฝ”๋“œ ์ค‘๋ณต์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ํŠน์ • repo ์•ˆ์— ๋‹ค๋ฅธ repo ๋ฅผ ์—ฐ๊ฒฐํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉด ์ค‘๋ณต์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, git subtree ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๊ฐ€๋Šฅํ•˜๋‹ค. (๋ฆฌ๋ˆ…์Šค์—์„œ์˜ symbloic link ์™€ ๋น„์Šทํ•˜๋‹ค๊ณ  ํ•ด์•ผํ• ๊นŒ?)

- ๋ฉ”์ธ repo : mysite
- ์„œ๋ธŒ repo : utils (์—ฐ๊ฒฐํ•  repo)

 

๋ฉ”์ธ repo ์˜ ์ตœ์ƒ์œ„ ํด๋”์—์„œ ์•„๋ž˜ ๋ช…๋ น์„ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰

 

1. remote ์— ์—ฐ๊ฒฐํ•  repo ๋“ฑ๋ก

$ git remote add [remote ์ด๋ฆ„] [์—ฐ๊ฒฐํ•  repo ์ฃผ์†Œ]
$ git remote add utils https://github.com/okojj/utils.git

 

2. ๋“ฑ๋ก๋œ remote ํ™•์ธ

$ git remote -v
origin	https://github.com:okojj/mysite.git (fetch)
origin	https://github.com/okojj/mysite.git (push)
utils	https://github.com/okojj/utils.git (fetch)
utils	https://github.com/okojj/utils.git (push)

 

3. git subtree ๋ช…๋ น์œผ๋กœ ์—ฐ๊ฒฐ ๋“ฑ๋ก

$ git subtree add --prefix=[์ƒ์„ฑํ• ํด๋”๋ช…]  [์—ฐ๊ฒฐํ•  repo ์ด๋ฆ„]  [์—ฐ๊ฒฐํ•  repo์˜ branch]
$ git subtree add --prefix=utils utils main
git fetch utils main
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 11 (delta 1), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (11/11), 1.77 KiB | 362.00 KiB/s, done.
From github.com:okojj/utils
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> utils/main
Added dir 'utils'

๋กœ์ปฌ์— ์ƒ์„ฑ๋œ utils ํด๋” ํ™•์ธ

 

4. git push ๋กœ remote ์— ๋“ฑ๋ก

$ git push
Enumerating objects: 14, done.
Counting objects: 100% (14/14), done.
Delta compression using up to 2 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (13/13), 2.19 KiB | 2.19 MiB/s, done.
Total 13 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:okojj/mysite.git
   6f7327c..b79940f  main -> main

 

5. subtree ํด๋” ์›๊ฒฉ์—์„œ ๋‚ด๋ ค๋ฐ›๊ธฐ (pull)

subtree ๋กœ ์ถ”๊ฐ€ํ•œ ํด๋”์— ์—…๋ฐ์ดํŠธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ๋ฐ˜์˜ํ•˜๋Š” ๋ฐฉ๋ฒ•

$ git subtree pull --prefix=utils utils main

 

6. subtree ํด๋”๋ฅผ ์›๊ฒฉ์— ๋ฐ˜์˜ํ•˜๊ธฐ (push)

subtree ํด๋” ๋‚ด์— ๋ณ€๊ฒฝ์‚ฌํ•ญ์— ๋Œ€ํ•ด remote ์— ๋ฐ˜์˜ํ•˜๋Š” ๊ฒฝ์šฐ

$ git subtree push --prefix=utils utils main

 

๋ฐ˜์‘ํ˜•