๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Git & GitHub

[Git / GitHub] - git subtree ๋ช…๋ น์–ด

by ์ฃผ๋ฐœ2 2021. 1. 17.
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š”? ์ด์ „์— ์šด์˜ํ•˜๋˜ ๋ธ”๋กœ๊ทธ์™€ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” GitHub๊ฐ€ ๋”ฐ๋กœ ์žˆ์Šต๋‹ˆ๋‹ค.

๋„ค์ด๋ฒ„ ๋ธ”๋กœ๊ทธ

GitHub


 

โœ” Git - subtree

์•ˆ๋…•ํ•˜์„ธ์š”, ์ด๋ฒˆ์— ์ •๋ฆฌํ•  ๋‚ด์šฉ์€ git์—์„œ subtree๋ฅผ ํ™œ์šฉํ•œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์•ˆ์— ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ €์žฅํ•˜๊ธฐ ์ž…๋‹ˆ๋‹ค.

repo

์œ„ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋“ค์–ด๊ฐ€๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.


3-repo

์œ„ ์‚ฌ์ง„์—์„œ ๋ณด์‹œ๋ฉด ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋‚ด๋ถ€์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ธ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • fastcampus-java-admin
  • inflearn-docker
  • inflearn-spring-basic

๋”ฐ๋ผ์„œ ์œ„์™€ ๊ฐ™์ด ํด๋” ์•ˆ์— ํด๋”๋ฅผ ์ €์žฅํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.



โœ” ์ค€๋น„๋ฌผ

์šฐ์„  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‘ ๊ฐœ์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

  • ๋ถ€๋ชจ Repository
  • ์ž์‹ Repository

์—ฌ๊ธฐ์„œ ๋ถ€๋ชจ Repository๋Š” root(GitHub ํ”„๋กœํ•„์—์„œ ๋ณด์—ฌ์ง€๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ) ์ด๊ณ ,

์ž์‹ Repository๋Š” ๋ถ€๋ชจ Repository ๋‚ด๋ถ€์— ๋„ฃ์„ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์ž…๋‹ˆ๋‹ค.

๋˜ํ•œ git ์„ ์„ค์น˜ํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.


โœ” subtree

child-parent-repo

์ €๋Š” ์œ„์™€ ๊ฐ™์ด parent ๋ ˆํฌ์ง€ํ† ๋ฆฌ 1๊ฐœ์™€ child ๋ ˆํฌ์ง€ํ† ๋ฆฌ 2๊ฐœ๋ฅผ ์ค€๋น„ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ด์ œ parent-repo ๋‚ด๋ถ€์— child-repo1 ๊ณผ child-repo2 ๋ฅผ ๋„ฃ์–ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.



parent-repo ๋กœ ๊ฐ€์„œ clone์„ ํ†ตํ•ด ํด๋”๋ฅผ ๋ฐ›์Šต๋‹ˆ๋‹ค.

git-clone-copy

์œ„ ๋„ค๋ชจ ๋ฐ•์Šค๋ฅผ ๋ˆ„๋ฅด๋ฉด repository์˜ url์ด ๋ณต์‚ฌ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.



๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ฐ›๊ณ  ๊ฒฝ๋กœ๋ฅผ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

git-init

git init ๋ช…๋ น์–ด์™€ git clone ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋ฐ›๊ณ , cd ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํด๋”๋ฅผ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.



child์˜ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ remote๋กœ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

git-remote-add

$ git remote add (remote name) (git ์ฃผ์†Œ)

  • remote name์—๋Š” ์„ค์ •ํ•œ name์ด remote์˜ name์ด ๋ฉ๋‹ˆ๋‹ค.
  • git ์ฃผ์†Œ์—๋Š” child ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ url์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค.(์œ„์—์„œ parent์˜ url์„ ๋ณต์‚ฌํ•œ ๋ฐฉ์‹์œผ๋กœ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.)
  • $ git remote -v ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด remote๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



git subtree ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.

git-subtree-add

$ git subtree add --prefix=<parent ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ €์žฅํ•  ํด๋”๋ช…> <child์˜ remote ์ด๋ฆ„> <์›๊ฒฉ branch name>

  • parent ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ €์žฅํ•  ํด๋”๋ช…: ์—ฌ๊ธฐ์— ์„ค์ •ํ•œ name์œผ๋กœ repository์— ํด๋”๋ช…์ด ์ง€์ •๋ฉ๋‹ˆ๋‹ค.
  • child์˜ remote ์ด๋ฆ„: ์œ„์—์„œ ์„ค์ •ํ•œ child์˜ remote๋ฅผ ์ง€์ •ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
    • child1, child2
  • ์›๊ฒฉ branch name: parent ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ๋ธŒ๋žœ์น˜๋ช…์„ ์ž‘์„ฑํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

$ git push

  • ์œ„ ๊ณผ์ •์ด ๋๋‚œ ํ›„ push๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด parent์˜ repository์— child1, child2 repository๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

test1

์ถ”๊ฐ€๋กœ ์ด๋ ‡๊ฒŒ ์ž‘์—…ํ•˜์‹  ํ›„ child1, child2 ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์‚ญ์ œํ•˜๋”๋ผ๋„ commit ๋‚ด์—ญ์ด ์œ ์ง€๋ฉ๋‹ˆ๋‹ค!!

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€