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
๋ฐ์ํ