๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ GitHub & Git

[GitHub & Git] Git Branch ๊ด€๋ จ ๋ช…๋ น์–ด ์ •๋ฆฌ

by A Lim Han 2023. 5. 30.

๐ŸŒฑ Git & GitHub์—์„œ์˜ Branch๋ž€?

 

 

๊นƒ(Git)๊ณผ ๊นƒํ—ˆ๋ธŒ(GitHub)์—์„œ์˜ branch๋ž€, ๊ฐœ๋ฐœ ์ž‘์—…์„ ๋…๋ฆฝ์ ์œผ๋กœ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์ƒ์„ฑ๋˜๋Š” ๊ฐ€์ง€๋‚˜ ๋ถ„๊ธฐ๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
๊ธฐ๋ณธ์ ์œผ๋กœ master (๋˜๋Š” main) ๋ธŒ๋žœ์น˜๊ฐ€ ์ƒ์„ฑ๋˜์–ด ์žˆ๊ณ , branch ์ƒ์„ฑ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ด master ๋ธŒ๋žœ์น˜์—์„œ ๋ถ„๊ธฐํ•˜์—ฌ ๋ณ„๋„์˜ ์ž‘์—… ๊ณต๊ฐ„์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค.

 

 

 


 

๐ŸŒฑ Git Branch ๊ด€๋ จ ๋ช…๋ น์–ด ์ •๋ฆฌ

 

0. Git Bash์—์„œ์˜ Branch ์ž‘์—…์„ ์œ„ํ•œ ์‚ฌ์ „ ์ž‘์—… (Clone)

-->  https://alim11.tistory.com/340

 

[GitHub & Git] Git Clone ๊ธฐ๋Šฅ ์‚ฌ์šฉ๋ฒ•

๐ŸŒธ GitHub Clone ๊ธฐ๋Šฅ์ด๋ž€? ์›๊ฒฉ ์ €์žฅ์†Œ(๊นƒํ—ˆ๋ธŒ ์ €์žฅ์†Œ)๋ฅผ ๋กœ์ปฌ ํ™˜๊ฒฝ์œผ๋กœ ๋ณต์ œํ•˜๋Š” ๊ธฐ๋Šฅ์„ Clone ์ด๋ผ๊ณ  ํ•œ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์›๊ฒฉ ์ €์žฅ์†Œ์— ์žˆ๋Š” ์ฝ”๋“œ์™€ ํŒŒ์ผ์„ ๋กœ์ปฌ ์ปดํ“จํ„ฐ๋กœ ๊ฐ€์ ธ์™€ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ,

alim11.tistory.com

 


 

1. Branch ์ถ”๊ฐ€

$ git branch "์ƒ์„ฑํ•  branch๋ช…"

one, two ์ด 2๊ฐœ์˜ branch๋ฅผ ์ถ”๊ฐ€ํ•จ

 


 

2. Branch ์ด๋™

$ git checkout "์ด๋™ํ•  branch๋ช…"

๋‹จ, ์ด๋™ํ•  branch๋Š” ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•ด๋†“์•„์•ผ ํ•œ๋‹ค.

 


 

3. Branch ์‚ญ์ œ

$ git branch -d "์‚ญ์ œํ•  branch๋ช…"

branch two ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์‚ญ์ œ๋˜์—ˆ์Œ์„ ํ™•์ธ

 


 

4. Branch ์ถ”๊ฐ€ ํ›„ ์ด๋™ ๋‹จ์ถ•ํ‚ค

$ git checkout -b "์ƒ์„ฑ ํ›„ ์ด๋™ํ•  branch๋ช…"

'three' ๋ผ๋Š” ์ด๋ฆ„์˜ branch๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ด๋™

 


 

5. ์ƒ์„ฑ๋œ Branch ๋ชฉ๋ก ํ™•์ธ

$ git branch

branch two ์‚ญ์ œ ์ „ ์‚ฌ์ง„์ž„

 


 

๐ŸŒฑ Git Bash์—์„œ์˜ Branch ์ˆ˜์ • ์‚ฌํ•ญ์„ GitHub Repo์— ๋ฐ˜์˜ํ•˜๊ธฐ

 

1. GitHub ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ๋“ค์–ด๊ฐ€๋ณด์•˜์œผ๋‚˜, ์ถ”๊ฐ€ํ•œ Branch๋“ค์ด ๋ณด์ด์ง€ ์•Š์Œ

2. Git Bash ์˜คํ”ˆ ํ›„ ์•„๋ž˜ ๋ช…๋ น์–ด๋“ค ์ˆœ์ฐจ์ ์œผ๋กœ ์‹คํ–‰

$ cd "๋ ˆํฌ์ง€ํ† ๋ฆฌ ํŒŒ์ผ ๊ฒฝ๋กœ"  #1 ์ž‘์—…์„ ๋™๊ธฐํ™”ํ•  ํŒŒ์ผ ๊ฒฝ๋กœ๋กœ ์ด๋™

$ git remote  #2 origin ์ด ์ •์ƒ์ ์œผ๋กœ ์ƒ์„ฑ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธ

$ git push origin "๋ฐ˜์˜ํ•  ์‚ฌํ•ญ"  #3 ํ•„์ž๋Š” ๋ณ„๋„์˜ ๋ฐ˜์˜ ์‚ฌํ•ญ ์—†์ด branch three๋งŒ ์ถ”๊ฐ€

3. ๋‹ค์‹œ GitHub ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ๋“ค์–ด๊ฐ€ branch๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด, ์ •์ƒ์ ์œผ๋กœ 'three' ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.