Home [GIT] Git์—์„œ Branch Merge ํ•˜๊ธฐ
Post
Cancel

[GIT] Git์—์„œ Branch Merge ํ•˜๊ธฐ

๐Ÿ“Œ GIT Merge!

image

Git์„ ์‚ฌ์šฉํ•˜๋‹ค๋ณด๋ฉด, Branch๋ฅผ ๋‚˜๋ˆ„๊ฒŒ ๋˜๊ณ , Branch๋ฅผ ๋‚˜๋ˆ„๊ณ  ๋ณ‘ํ•ฉํ•˜๋Š” ๊ณผ์ •์„ ๊ผญ ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.
์ด๋ฒˆ์— Spring ํ•ต์‹ฌ์„ ๊ณต๋ถ€ํ•˜๋ฉด์„œ, ์ด๋ฏธ ๋งŒ๋“ค์–ด์ง„ ์ž๋ฐ”ํŒŒ์ผ๊ณผ ๊นƒํ—ˆ๋ธŒ์— READMEํŒŒ์ผ๋งŒ ๋„ฃ๊ณ  ๋ฏธ๋ฆฌ ํŒŒ๋†“์€ repo๋ฅผ ๋ณ‘ํ•ฉํ•˜๋ฉด์„œ ์ž ๊น ํ•ด๋ฉ”๋˜ ๋‚ด์šฉ๊ณผ ์†”๋ฃจ์…˜์„ ๊ณต์œ ํ• ๊ฒธ ๋ฉ”๋ชจํ•˜๋ ค๊ณ  ํ•œ๋‹ค.

๐Ÿ“Ž ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๋ณ‘ํ•ฉํ•˜๊ธฐ ์œ„ํ•œ ๊ณผ์ •

์ฒซ๋ฒˆ์งธ๋กœ ๋ณ‘ํ•ฉํ•  ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

1
$ git remote add <๋ณ‘ํ•ฉํ•  ์›๊ฒฉ ์ €์žฅ์†Œ ์ด๋ฆ„> <๋ณ‘ํ•ฉํ•  ์›๊ฒฉ ์ €์žฅ์†Œ ์ฃผ์†Œ>

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ฃผ์†Œ๋ฅผ ์ง€์ •ํ•ด์ค˜์„œ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๋กœ์ปฌ ์ €์žฅ์†Œ์™€ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ์—ฐ๊ฒฐํ•ด์ค€๋‹ค.

1
$ git fetch <๋ณ‘ํ•ฉํ•  ์›๊ฒฉ ์ €์žฅ์†Œ ์ด๋ฆ„>

์›๊ฒฉ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹ ๊ธฐ๋ก๋“ค์„ ๊ฐ€์ ธ์˜จ๋‹ค. ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹๋“ค์„ ๊ฐ€์ ธ์™€ ํŒŒ์ผ ์ด๋ฆ„์€ ๋ฌธ์ œ๊ฐ€ ์—†๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. ๋‚ด์šฉ์ด ๊ฐ™๋‹ค๋ฉด ๊ทธ๋ƒฅ pull๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด๋„ ๋˜์ง€๋งŒ, ๋งŒ์•ฝ ๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด fetchํ›„ merge๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ •์„ฑ์ด ๋†’๋‹ค.

๐Ÿ“Ž ๊ธฐ๋ก๋“ค์„ ๋ณ‘ํ•ฉ

1
$ git merge --allow-unrelated-histories <๋ณ‘ํ•ฉํ•  ์›๊ฒฉ ์ €์žฅ์†Œ ์ด๋ฆ„>/<๋ณ‘ํ•ฉํ•˜๊ณ  ์‹ถ์€ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ branch ์ด๋ฆ„>

๊ทธ๋ƒฅ git merge๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด ์ด์ „ ์ปค๋ฐ‹๊ธฐ๋ก๊ณผ ์—ฐ๊ฒฐ์ด ๋˜์ง€ ์•Š์•„์„œ merge์ž์ฒด๊ฐ€ ์ž˜ ๋˜์ง€ ์•Š๋Š”๋‹ค. ์ด๋•Œ ์ข‹์€ ๋ฐฉ๋ฒ•์ด --allow-unrelated-histories ์˜ต์…˜์ด๋‹ค. ์ปค๋ฐ‹๊ธฐ๋ก๋„ ๋ณ‘ํ•ฉํ•˜๋„๋ก ํ—ˆ์šฉํ•˜๋Š” ์˜ต์…˜์œผ๋กœ push์‹œ์—๋„ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

์ดํ›„, remote remove๋ฅผ ํ†ตํ•ด์„œ ์ด๋ฏธ ์กด์žฌํ•˜๋˜ ์ €์žฅ์†Œ๋ฅผ ์ง€์šฐ๊ณ , Local์˜ ์ €์žฅ์†Œ๋ฅผ ์ปค๋ฐ‹ํ•˜๋ฉด ๋œ๋‹ค.

์œ„์˜ ๊ณผ์ •์ค‘ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ณผ์ •์ด ๋ฐ”๋กœ ๋ณ‘ํ•ฉ๊ณผ์ •์ด๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค, merge๋ช…๋ น์–ด ์ค‘์—์„œ ์ปค๋ฐ‹๊ธฐ๋ก์ด ์—ฐ๊ฒฐ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์‚ฌ์‹ค์„ ๋ชจ๋ฅธ๋‹ค๋ฉด ์•„๋งˆ ํ•ด๊ฒฐํ•˜์ง€ ๋ชปํ–ˆ์„ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค.

๐Ÿ“– ์ฐธ๊ณ ์ž๋ฃŒ

https://velog.io/@www_1216/%EC%84%9C%EB%A1%9C-%EB%8B%A4%EB%A5%B8-%EB%91%90-%EC%9B%90%EA%B2%A9-%EC%A0%80%EC%9E%A5%EC%86%8C-%EB%B3%91%ED%95%A9%ED%95%98%EA%B8%B0 https://cheonmro.github.io/2019/04/13/merge-branches/

This post is licensed under CC BY 4.0 by the author.

[BLOG] Git vs Perforce

[PeachTri] DB ์ƒ์„ฑ