IT Talks

git subtree - repository 내에 λ‹€λ₯Έ repository link ν•˜κΈ°

OkOJJ 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

 

728x90