let's get IT with DAVINA ๐Ÿ’ป

Github ๋ณธ๋ฌธ

DEV_IN/Git&Github

Github

๋‹ค๋นˆ์น˜์ฝ”๋“œ๐Ÿ’Ž 2023. 2. 8. 21:12
โญ <๊ฐœ๋… ์•Œ๊ณ  ๊ฐ€์ž>
git ⇒ ๋ฒ„์ „ ๊ด€๋ฆฌ ํ”„๋กœ๊ทธ๋žจ
repository ⇒ git์ด ํŒŒ์ผ ๊ธฐ๋กํ•ด๋‘๋Š” ์žฅ์†Œ
์›๊ฒฉ ์ €์žฅ์†Œ = ์˜จ๋ผ์ธ repository
- ์ปดํ“จํ„ฐ ๊ณ ์žฅ๋‚˜๋„ ์•ˆ์‹ฌ
- ํ˜‘์—…์ด ๊ฐ€๋Šฅ
- ex) github

๋‚ด ์ฝ”๋“œ ์˜ฌ๋ฆด ๋•? git push

//local ํ™˜๊ฒฝ์—์„œ repository ์ƒ์„ฑ
git init

//๊ธฐ๋ณธ๋ธŒ๋žœ์น˜ ์ด๋ฆ„์„ main์œผ๋กœ ๋ฐ”๊พธ๊ธฐ
git branch -M main

//๋กœ์ปฌ -> ์›๊ฒฉ์œผ๋กœ ๋ณด๋‚ด๊ธฐ
git push -u ์›๊ฒฉ์ €์žฅ์†Œ์ฃผ์†Œ ์˜ฌ๋ฆด๋กœ์ปฌ๋ธŒ๋žœ์น˜๋ช…

//์›๊ฒฉ์ €์žฅ์†Œ์ฃผ์†Œ ๋„˜ ๊ธธ์–ด์„œ -> ๋ณ€์ˆ˜ ๋ฌธ๋ฒ• ์‚ฌ์šฉํ•˜๊ธฐ
git remote add ๋ณ€์ˆ˜๋ช… ์ฃผ์†Œ
git push -u ๋ณ€์ˆ˜๋ช… ์˜ฌ๋ฆด๋กœ์ปฌ๋ธŒ๋žœ์น˜๋ช… //์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์ง!

//-u๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ทธ ์ดํ›„๋ถ€ํ„ฐ ์ฃผ์†Œ๊ฐ€ ๊ธฐ์–ต๋˜๊ธฐ ๋•Œ๋ฌธ์— 
git push //๋งŒ ํ•ด๋„ ์ž๋™์œผ๋กœ ๋ณด๋‚ด์ง„๋‹ค!

ํƒ€์ธ๊ณผ ํ˜‘์—…ํ•˜๊ธฐ? git clone, pull

#์†Œ์Šค์ฝ”๋“œ ๋‚ด ๋กœ์ปฌ์— ๋‹ค์šด๋ฐ›์•„์˜ค๊ธฐ
git clone ์ €์žฅ์†Œ์ฃผ์†Œ

#์›๊ฒฉ์ €์žฅ์†Œ์— ๋‹ค๋ฅธ ํŒ€์›์ด pushํ•œ ์ƒˆ๋กœ์šด ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์ƒ๊ธฐ๋ฉด ๋‚œ push๋ฅผ ๋ชปํ•˜๊ฒŒ ๋œ๋‹ค. 
#๊ทธ ์›๊ฒฉ์ €์žฅ์†Œ -> ๋กœ์ปฌ์ €์žฅ์†Œ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
git pull ์›๊ฒฉ์ €์žฅ์†Œ์ฃผ์†Œ ๋ธŒ๋žœ์น˜๋ช…
//or
git pull origin(๋ณ€์ˆ˜๋ช…) ๋ธŒ๋žœ์น˜๋ช…

#pull๋กœ ๋ฐ›์•„์˜จ ๋‹ค์Œ ๋‚ด ๋ณ€๋™ ์‚ฌํ•ญ pushํ•ด~!
#ํŒ€์›๋„ ๋‚ด๊บผ ๋‹ค์‹œ pull๋กœ ๋ฐ›์•„๊ฐ€๊ณ  ๋‹ค์‹œ pushํ•ด~!
  • git fetch = ์›๊ฒฉ์ €์žฅ์†Œ์— ์žˆ๋Š” commit ์ค‘์— ๋กœ์ปฌ์— ์—†๋Š” ์‹ ๊ทœ commit ๊ฐ€์ ธ์™€
  • git merge = ๊ทธ๊ฑธ mergeํ•ด
  • git pull = git fetch + git merge
โ›”๏ธ Error Issue
feat/front/all branch์—์„œ ์ž‘์—…ํ•˜๊ณ  ๋‹ค์†œ๋‹˜์ด ๋กœ์ปฌ์˜ dev/front๋ธŒ๋žœ์น˜์—์„œ pull์„ ๋ฐ›์•„์˜ค๋ ค๊ณ  ํ–ˆ์œผ๋‚˜, dev/front์—์„œ feat๋ธŒ๋žœ์น˜๊ฐ€ ์ž๋™ ๋ณ‘ํ•ฉ์ด ๋˜๋ฉด์„œ ๊ฐ€์ ธ์™€์ง.

→ ์ด๋Ÿด๋•, ๋‹ค์†œ๋‹˜ ๋กœ์ปฌ์—์„œ ๋™์ผํ•œ ๋ธŒ๋žœ์น˜๋ฅผ ์ƒˆ๋กœ ์ƒ์„ฑํ•œ ํ›„, git pull์„ ๋ฐ›์•„์™€์•ผ merge๋ฅผ ํ”ผํ• ์ˆ˜์žˆ์Œ!

โ›”๏ธ Error Issue

gitignore์— node modulues๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํŒŒ์ผ์ด ์ปค push๋˜์ง€ ์•Š์Œ!
๊ทธ๋ž˜์„œ git clone ํ•ด์„œ ๋ฐ›์•„์™€๋„ node modules ์•ˆ๊น”๋ฆผ (package.json์€ ์กด์žฌํ•˜๊ณ , npm install ํ•˜๋ฉด uptodate์ด๋ผ๊ณ  ๋œธ)

⇒ ์›ํ•˜๋Š” ๋””๋ ‰ํ† ๋ฆฌ ex)”front” ์—์„œ ํ†ตํ•ฉ ํ„ฐ๋ฏธ๋„์„ ํ‚จ ๋‹ค์Œ npm install์„ ๋‹ค์‹œ ํ•ด์คŒ์œผ๋กœ์จ ํ•ด๊ฒฐ
(์ด ๋•Œ, front์—์„œ ํ†ตํ•ฉ ํ„ฐ๋ฏธ๋„์„ ํ‚ค์ง€ ์•Š์•„์„œ ์—๋Ÿฌ๋„ ๋˜ ๋ฐœ์ƒํ–ˆ์—ˆ์Œ...)



๋ธŒ๋žœ์น˜๋กœ ํ˜‘์—…ํ•˜๊ธฐ? pull request

github์—์„œ ์ง์ ‘ ๋ธŒ๋žœ์น˜ ๋งŒ๋“ค์–ด๋„ ๋˜๊ณ ,

๋กœ์ปฌ์ €์žฅ์†Œ์—์„œ ๋ธŒ๋žœ์น˜ ๋งŒ๋“ค๊ณ  mergeํ•ด๋„ ๋˜‘๊ฐ™์Œ

#branch ์ƒ์„ฑ
git branch ๋‰ด๋ธŒ๋žœ์น˜๋ช…

#ํ•ด๋‹น branch๋กœ ์ด๋™
git switch ๋‰ด๋ธŒ๋žœ์น˜๋ช…

git add .
git commit -m "๋ฉ”์„ธ์ง€"
git push [์ €์žฅ์†Œ์ด๋ฆ„] [๋‰ด๋ธŒ๋žœ์น˜๋ช…]

์ƒ๊ธฐ ๋‚ด์šฉ๊นŒ์ง€ ์™„๋ฃŒ๋˜๋ฉด Github์œผ๋กœ ์™€!!

main branch๋กœ ํ•ด๋‹น ๋‰ด๋ธŒ๋žœ์น˜๋ฅผ mergeํ•˜๊ธฐ ์ „ ์ฝ”๋“œ๋ฆฌ๋ทฐ ํ•„์š”! => pull request!

ํŒ€์› ๋˜๋Š” ํŒ€์žฅ์—๊ฒŒ ์ฝ”๋“œ ๋ฆฌ๋ทฐ ๋ฐ›๊ณ  → merge ๋‹ด๋‹น์ž๊ฐ€ merge ์Šน์ธํ•˜๋ฉด ๋จ~

<merge ๋ฐฉ๋ฒ•>
- rebase and merge - ๋ณ€๊ฒฝ ์‚ฌํ•ญ, ๋ชจ๋“  ์‚ฌํ•ญ์ด ๋ฐ€๋ ค ์˜ฌ๋ผ๊ฐ€๋Š” ๋Š๋‚Œ์œผ๋กœ merge๋œ๋‹ค.
- squash and merge - ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ํ•˜๋‚˜๋กœ ํ•ฉ์ณ์ ธ์„œ ๋”ฑ 1๊ฐœ์˜ ์ ์ด merge๋œ๋‹ค.
- merge commit - ๋ณ€๊ฒฝ ์‚ฌํ•ญ ๋‹ค ๊ฐ€์ ธ์˜ค๊ณ , ๊ทธ ์œ„์— ํ•ฉ์ณ์ง„ merge commit ์  1๊ฐœ๋„ ๋”ฑ ์ฐ๊ธฐ

์ฝ”๋“œ ์ž ๊น ๋ณด๊ด€? git stash

์ฃผ์„ ์ฒ˜๋ฆฌํ•˜๋ฉด ๋˜์ง€ ์™œ stash์จ?

commit ํ• ๋•Œ ์ฃผ์„๋„ ๋‹ค๊ฐ™์ด ์˜ฌ๋ผ๊ฐ€๊ธฐ ๋•Œ๋ฌธ์— ๊น”๋”ํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ~

#๋ฐฉ๊ธˆ ์นœ ์ฝ”๋“œ ์ž ๊น ์ž˜๋ผ๋‚ด์„œ ๋ณด๊ด€ ์ข€
git stash 

#๋ณด๊ด€๋œ ์ฝ”๋“œ ๋ชฉ๋ก ์กฐํšŒ => ์ตœ๊ทผ commit๊ณผ์˜ ์ฐจ์ด์ ์„ ์ „๋ถ€ ๋ณด๊ด€ํ•ด์คŒ
#but staging ์•ˆํ•ด๋†“์€ ์ƒˆ๋กœ์šด ํŒŒ์ผ์€ stash ์•ˆ๋ ์ˆ˜๋„ ์žˆ์–ด
git stash list

#๋ฉ”๋ชจ๋„ ์ ๊ณ  ์‹ถ์œผ๋ฉด
git stash save "๋ฉ”๋ชจ"

#stash๋œ ์ฝ”๋“œ ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
#๊ฐ€์žฅ ์ตœ๊ทผ ๊ฒƒ๋ถ€ํ„ฐ ๋ถˆ๋Ÿฌ์˜ด
git stash pop 

#stash 1๊ฐœ ์‚ญ์ œ๋Š” 
git stash drop ๋ฒˆํ˜ธ

#์ „๋ถ€ ์‚ญ์ œ๋Š”
git stash clear

 

'DEV_IN > Git&Github' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Git VS Github  (0) 2023.02.08
Git Flow  (4) 2023.02.08
Git [๋‚ด ์‹ค์ˆ˜ ๋ณต๊ตฌํ•˜๊ธฐ] ๊ณผ๊ฑฐ๋กœ ์“ฉ ๐Ÿ’จ  (4) 2023.02.08
Git [merge]  (3) 2023.02.08
Git [installation & branch ์ƒ์„ฑ]  (0) 2023.02.08
Comments