๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
FOR SW ENGINEER๐Ÿ‘ฉ‍๐Ÿ’ป/GIT

๊ตญ๋น„์ˆ˜์—… DAY-14 (2)(Git์‚ฌ์šฉ๋ฒ•)

by ์”จ๋‹ˆ 2021. 9. 5.
728x90

Git๋‘๋ฒˆ์งธ๋กœ๊ทธ!!

์ถ”๊ฐ€์ ์ธ Git ๋ช…๋ น์–ด์— ๊ด€ํ•œ ์š”์ !

 

1. ํ•œ ์‚ฌ๋žŒ์ด ์—ฌ๋Ÿฌ๊ฐœ์˜ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๋‹ค๋ฃฐ๋•Œ!

โ–ถ git remote -v :  ๋‹ค๋ฃจ๊ณ  ์žˆ๋Š” ์›๊ฒฉ์ €์žฅ์†Œ๋“ค ํ™•์ธ

ํ˜„์žฌ ์—ฐ๊ฒฐ๋œ ์›๊ฒฉ์ €์žฅ์†Œ ํ™•์ธ
๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋‹ค๋ฅธ ์›๊ฒฉ์ €์žฅ์†Œ(origin2)๋ฅผ ์ถ”๊ฐ€ํ•ด remote -v๋กœ ์ถ”๊ฐ€๋จ์„ ํ™•์ธํ•จ.

 

โ–ถ git remote rm/remove ์‚ญ์ œํ•˜๊ณ  ์‹ถ์€ ์›๊ฒฉ์ €์žฅ์†Œ์ด๋ฆ„ : ์›ํ•˜๋Š” ์›๊ฒฉ์ €์žฅ์†Œ ์‚ญ์ œ

์œ„์—์„œ ์ถ”๊ฐ€ํ–ˆ๋˜ ๋‘๋ฒˆ์งธ ์›๊ฒฉ์ €์žฅ์†Œ(origin2)๋ฅผ ์‚ญ์ œํ•˜๊ฒ ์Œ.

remote rm์œผ๋กœ origin2๋ฅผ ์‚ญ์ œํ•˜์˜€๊ณ , remote -v๋ฅผ ํ†ตํ•ด origin2๊ฐ€ ์‚ญ์ œ๋˜์—ˆ์Œ์„ ํ™•์ธ

 

 

2. ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ํ•˜๋‚˜์˜ ์›๊ฒฉ์ €์žฅ์†Œ๋ฅผ ๋‹ค๋ฃฐ๋•Œ! - git branch์‚ฌ์šฉ

โ–ถ git branch ์ด๋ฆ„ : ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ

  ๊ธฐ๋ณธ master๋ง๊ณ  ์ž์‹ ์ด ์›ํ•˜๋Š”, ํ˜น์€ ์ž์‹ ์ด ๋งก์€ ์ด๋ฆ„์œผ๋กœ branch์ด๋ฆ„์„ ์„ค์ •ํ•ด ์ƒ์„ฑํ•จ.

3๊ฐœ์˜ branch์ƒ์„ฑ

 

โ–ถ git branch : ๋ธŒ๋žœ์น˜ ํ™•์ธ

๋ธŒ๋žœ์น˜ ํ™•์ธ, ํ˜„์žฌ branch๋Š” ์ดˆ๋ก์ƒ‰์œผ๋กœ ๋‚˜ํƒ€๋‚จ

 

โ–ถ git checkout ๋ณ€๊ฒฝ ์›ํ•˜๋Š” ๋ธŒ๋žœ์น˜ ๋ช… : ๋ธŒ๋žœ์น˜ ๋ณ€๊ฒฝ

master์—์„œ siyoon ๋ธŒ๋žœ์น˜๋กœ ๋ณ€๊ฒฝ

< branch ๋ณ€๊ฒฝํ›„ > 

siyoonbranchํŒŒ์ผ ์ƒ์„ฑ

 

- ๋‹ค์‹œ master๋ธŒ๋žœ์น˜๋กœ ๋ฐ”๊พธ๋ฉด

siyoon -> master ๋ธŒ๋žœ์น˜ ๋ณ€๊ฒฝ

siyoon๋ธŒ๋žœ์น˜์—์„œ ์ƒ์„ฑํ–ˆ๋˜ siyoonbranch๋ณผ์ˆ˜ ์—†์Œ.

 

- siyoon๋ธŒ๋žœ์น˜์—์„œ ์›๊ฒฉ์ €์žฅ์†Œ๋กœ ์˜ฌ๋ฆด๋•Œ

git push origin master ๊ฐ€ ์•„๋‹ˆ๋ผ git push origin siyoon์œผ๋กœ ์˜ฌ๋ ค์•ผ ํ•จ.

์›๊ฒฉ์ €์žฅ์†Œ์—๋„ siyoon๋ธŒ๋žœ์น˜๊ฐ€ ํ•˜๋‚˜ ์ƒ์„ฑ๋˜๊ณ 

siyoon๋ธŒ๋žœ์น˜ ๋‚ด siyoonbranchํ…์ŠคํŠธํŒŒ์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ commit๋์Œ์„ ํ™•์ธํ• ์ˆ˜ ์žˆ์Œ.

 

โ–ถ git branch -D ์‚ญ์ œํ•˜๊ณ ์‹ถ์€ ๋ธŒ๋žœ์น˜ ๋ช… : ๋ธŒ๋žœ์น˜ ์‚ญ์ œ

- ์œ„์—์„œ ํŒŒ์ผ์ด ์žˆ๋Š” ๋ธŒ๋žœ์น˜ siyoon, mater๋ฅผ ์ œ์™ธํ•˜๊ณ  ํŒŒ์ผ์ด ์—†๋Š” ๋‚˜๋จธ์ง€ ๋ธŒ๋žœ์น˜ java, gitMaker์‚ญ์ œ.

- ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค์—ˆ๋˜ ๋ธŒ๋žœ์น˜ ์žฅ์†Œ์—์„œ ์‚ญ์ œํ•˜๋„๋ก ํ•จ!

- ์œ„์—์„œ master์—์„œ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค์—ˆ๊ธฐ ๋•Œ๋ฌธ์— master๋ธŒ๋žœ์น˜์—์„œ java, gitMaker๋ธŒ๋žœ์น˜ ์‚ญ์ œ.

java branch์™€ gitMaker๋ธŒ๋žœ์น˜๊ฐ€ ์‚ญ์ œ๋œ๊ฒƒ์„ ํ™•์ธ

 

โ–ถ git merge : ๊นƒ ๋ณ‘ํ•ฉํ•˜๊ธฐ

- master๋ธŒ๋žœ์น˜์—์„œ siyoon๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉ!

-mater์—์„œ siyoon๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—

master๋ธŒ๋žœ์น˜์—์„œ๋„ siyoon๋ธŒ๋žœ์น˜์—์„œ ๋งŒ๋“ค์—ˆ๋˜ ํ…์ŠคํŠธํŒŒ์ผ(siyoonbranch) ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ๋จ!

 

2. ์›๊ฒฉ์ €์žฅ์†Œ ์ƒํ˜ธ์ž‘์šฉ(์‹ค์งˆ์  ํ˜‘์—…)

-์›๊ฒฉ์ €์žฅ์†Œ๋Š” ๋˜๋‹ค๋ฅธ Repository์ผ๋ฟ!

โ–ถ 1. ์›๊ฒฉ์ €์žฅ์†Œ์— ์กฐํšŒ(์ถ”๊ฐ€) ํ•˜๊ธฐ

- git remote add <๋‹จ์ถ•์ด๋ฆ„ > ์ฃผ์†Œ

  ex) git remote add origin http://~~~~~

 

โ–ถ 2. ์›๊ฒฉ์ €์žฅ์†Œ์—  ์กฐํšŒ(์ถ”๊ฐ€) ํ•˜๊ธฐ

- git push origin master

- ๋‚ด ๋กœ์ปฌ ์ €์žฅ์†Œ๋Š” ๋ณ€ํ–ˆ๋Š”๋ฐ ์›๊ฒฉ์ €์žฅ์†Œ๊ฐ€ ๋ณ€ํ•˜์ง€ ์•Š์•˜์„๋•Œ,

  ๋‚˜์˜ ๋กœ์ปฌ์ €์žฅ์†Œ์— ์žˆ๋Š”๊ฒƒ์„ pushํ•ด์„œ ์›๊ฒฉ์ €์žฅ์†Œ์— ์ €์žฅ์‹œํ‚ด.

 

โ–ถ 3. ์›๊ฒฉ์ €์žฅ์†Œ์—์„œ ์–ป์–ด์™€์„œ ํ•ฉ์น˜๊ธฐ

- git pull (origin master)

==> origin์„ ๋‚˜์˜ ์ €์žฅ์†Œ๋กœ ๋ถˆ๋Ÿฌ์™€ ํ•ฉ์ณ๋ผ!

- ๋‚ด ๋กœ์ปฌ ์ €์žฅ์†Œ๋Š” ๋ณ€ํ•˜์ง€ ์•Š์•˜๋Š”๋ฐ ์›๊ฒฉ์ €์žฅ์†Œ๊ฐ€ ๋ณ€ํ–ˆ์„๋•Œ,

  ๋ณ€ํ™”๋œ ์›๊ฒฉ์ €์žฅ์†Œ์— ์žˆ๋Š”๊ฒƒ์„ ๋ถˆ๋Ÿฌ์™€ ๋‚˜์˜ ๋กœ์ปฌ ์ €์žฅ์†Œ์— ์žˆ๋Š”๊ฒƒ๊ณผ ํ•ฉ์นจ.

 

โ–ถ 4. ์›๊ฒฉ์ €์žฅ์†Œ์—์„œ ์–ป๊ธฐ

- git fetch(origin master)

==> origin์„ ๋‚˜์˜ ์ €์žฅ์†Œ๋กœ ๊ทธ๋Œ€๋กœ ๋ถˆ๋Ÿฌ์™€๋ผ!(์›๊ฒฉ์ €์žฅ์†Œ์— ์žˆ๋Š”๊ฒƒ์„ ๊ทธ๋Œ€๋กœ fetch)

 

โ–ถ5. ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ๋ณต์‚ฌํ•˜๊ธฐ

- git clone ์ฃผ์†Œ(http://~~~~)

==> ์›๊ฒฉ์ €์žฅ์†Œ์— ์žˆ๋Š”๊ฒƒ ๊ทธ๋Œ€๋กœ ๋ณต์‚ฌํ•ด์˜ค๊ธฐ

 

 

โ€ป  git push์™€ pull์‚ฌ์ด์—์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒํ• ์ˆ˜ ์žˆ์Œ!! ==> conflict (์ถฉ๋Œ)

- conflict๋Š” ๊ฐ™์€ ํŒŒ์ผ์„ ๋™์‹œ์— ์ˆ˜์ •ํ•  ๋•Œ ๋ฐœ์ƒํ•จ.

- ex) ๋กœ์ปฌ ์ €์žฅ์†Œ์—์žˆ๋Š” siyoonbranchํŒŒ์ผ์ด ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ์ˆ˜์ •์ด ๋˜์—ˆ๊ณ , ์›๊ฒฉ์ €์žฅ์†Œ์— ์žˆ๋Š” siyoonbranchํŒŒ์ผ์ด ์›๊ฒฉ์ €์žฅ์†Œ์—์„œ ์ˆ˜์ •์ด ๋˜์—ˆ์Œ. ์ด๋ฅผ ๋ชจ๋ฅด๊ณ  ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ์›๊ฒฉ์ €์žฅ์†Œ์˜ ํŒŒ์ผ์„ pullํ•  ๊ฒฝ์šฐ์— conflict๋ฐœ์ƒ!

 

โ–ถ conflictํ•ด์†Œ์ ˆ์ฐจ

 1. ์ถฉ๋Œ๋ฐœ์ƒ

 2. ์ผ๋‹จ ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ๋‚ด๊ฐ€ ์“ฐ๋˜ ์ฝ”๋“œ add -> commitํ•จ (commit์•ˆํ•˜๋Š” ๊ฒฝ์šฐ ๋‹จ์ˆœ ์—๋Ÿฌ๋งŒ ๋ฐœ์ƒ)

 3. ๋‹ค์‹œํ•œ๋ฒˆ pull ํ•จ -> conflict๋ฐœ์ƒ

 4. comflict ํŒŒ์ผ๋ชฉ๋ก ํ™•์ธ ํ›„ ์ฝ”๋“œ ์ˆ˜์ •

   -๋กœ์ปฌ ์ €์žฅ์†Œ / ์›๊ฒฉ์ €์žฅ์†Œ์—์„œ ์ž‘์„ฑํ•œ ์ฝ”๋“œ ์ค‘ ์›ํ•˜๋Š” ์ฝ”๋“œ๋กœ ์„ ํƒํ•ด ์ˆ˜์ •

conflict๊ฒฝ์šฐ ํŒŒ์ผ์— ๋‚˜ํƒ€๋‚˜๋Š” ์ฝ”๋“œ

5. ์ˆ˜์ • ํ›„ add -> commit -> push ๋กœ conflictํ•ด๊ฒฐ!

 

728x90

'FOR SW ENGINEER๐Ÿ‘ฉโ€๐Ÿ’ป > GIT' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๊ตญ๋น„์ˆ˜์—… DAY-14 (Git์‚ฌ์šฉ๋ฒ•)  (0) 2021.09.04