๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป Programming/programming

[git] git๊ณผ github๋ž€ & git ๋ช…๋ น์–ด ๋ชจ์Œzip in CLI

Hello, I'm Dona! 

์ œ๊ฐ€ ๋ณด๋ ค๊ณ  ๋งŒ๋“  git ๋ช…๋ น์–ด ๋ชจ์Œ์ž…๋‹ˆ๋‹ค๐Ÿ—‚

CLI ํ„ฐ๋ฏธ๋„์˜ ๊นŒ๋งŒ ํ™”๋ฉด์€ ์–ธ์ œ๋‚˜ ๋‚˜๋ฅผ ๋‹นํ™ฉ์ผ€ํ•˜์ง€๋งŒ, ์ €๋Š” ๊ตด๋ณตํ•˜์ง€ ์•Š์•„์š”๐Ÿ˜ค

ํ™”์ดํŒ…์ž…๋‹ˆ๋‹ค๐Ÿ’ช

* ์ด๋ฏธ์ง€๋Š” ์ง์ ‘ ppt๋กœ ์ œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค, ์‚ฌ์šฉํ•˜์‹ค ๋•Œ๋Š” ์ถœ์ฒ˜๋ฅผ ๋ฐํ˜€์ฃผ์„ธ์š”!

 


๐Ÿ” Git์€ ๋ญ๊ณ  GitHub๋Š” ๋ญ์˜ˆ์š”โ“

1. Git : ๋ฒ„์ „๊ด€๋ฆฌ(Version Control)์™€ ๋™์‹œ ํ˜‘์—…(Cooperation)์„ ํ•˜๊ฒŒํ•ด์ฃผ๋Š” Tool

2. GitHub : ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๋Œ€์‹  ์ œ๊ณตํ•ด์ฃผ๋Š” ์„œ๋น„์Šค, Git์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ๋“ค์„ ๋ฐฑ์—…ํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต๊ฐ„ 

 

โ˜‘๏ธ ๋ฒ„์ „ ๊ด€๋ฆฌ์˜ ์žฅ์ โ“

1. ์ง€๋‚œ ๊ณผ์ • ํ™•์ธ ๊ฐ€๋Šฅ

2. ์ด์ „ ๋ฒ„์ „์œผ๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ์Œ

 

โ˜‘๏ธ repository์™€ commitโ“

1. commit : ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ์˜ ํŠน์ • ๋ชจ์Šต์„ ํ•˜๋‚˜์˜ ๋ฒ„์ „์œผ๋กœ ๋‚จ๊ธฐ๋Š” ํ–‰์œ„ & ๊ฒฐ๊ณผ๋ฌผ

2. repository : ์ปค๋ฐ‹์ด ์ €์žฅ๋˜๋Š” ์ €์žฅ์†Œ

์ถœ์ฒ˜ : https://www.javatpoint.com/git-push
add, commit, reset, push
pull

1. add : loca์ƒ์˜ ์ˆ˜์ •์‚ฌํ•ญ โžก๏ธ staging area๋กœ

2. commit : staging area โžก๏ธ local repository์— commit ๊ธฐ๋ก

3. reset : commit ์ทจ์†Œ (์ˆ˜์ •ํ•˜๊ณ  ๋‹ค์‹œ ์˜ฌ๋ฆด ๋•Œ, ๋‹ค์‹œ add โžก๏ธ commitํ•ด์ฃผ์–ด์•ผ ํ•จ)

4. push : local repository โžก๏ธ remote repository(์˜ˆ๋ฅผ ๋“ค์–ด github)

5. pull : remote repository โžก๏ธ local repository

* local repository(๋กœ์ปฌ ์ €์žฅ์†Œ) : ํ˜„์žฌ ๋‚ด๊ฐ€ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” ๋‚ด PC์— ์ €์žฅ๋˜๋Š” ์ €์žฅ์†Œ

* remote repository(์›๊ฒฉ ์ €์žฅ์†Œ) : ์›๊ฒฉ ์„œ๋ฒ„์— ์ €์žฅ๋˜๊ณ  ๊ด€๋ฆฌ๋˜๋Š” ์ €์žฅ์†Œ


๐Ÿ—‚ git ๋ช…๋ น์–ด ๋ชจ์Œzip in CLI

1. ํ˜ผ์ž ์ž‘์—… 

# ๊นƒํ—™ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ๋ฅผ local๋กœ ๊ฐ€์ ธ์™€์„œ ์ž‘์—…
git clone url(๊นƒํ—™ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ ์ฃผ์†Œ) 

# ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์™€ ๋‚ด ๋กœ์ปฌ์˜ ๋ณ€ํ™”์ƒํƒœ ์œ ๋ฌด ํ™•์ธ
git status 

# local์˜ ์ˆ˜์ •์‚ฌํ•ญ -> staging area๋กœ ์˜ฎ๊ธฐ๊ธฐ
git add -A
git add . 

#  staging area -> local ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์— ์ปค๋ฐ‹ ๊ธฐ๋ก
git commit -m ‘message’

# [commit ์ทจ์†Œ]
# ๋ฐ”๋กœ ์ด์ „์œผ๋กœ reset -> ์ˆ˜์ •ํ•˜๊ณ  ๋‹ค์‹œ ์˜ฌ๋ฆฌ๊ณ  ์‹ถ์œผ๋ฉด, ์ˆ˜์ •ํ›„ staging area์˜ฌ๋ฆฌ๊ณ  commitํ•ด์ฃผ์–ด์•ผํ•จ
git reset HEAD^ 
# nํšŒ ์ด์ „์œผ๋กœ reset
git reset HEAD~n 

# local ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ -> ๊นƒํ—ˆ๋ธŒ ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ๋กœ push
git push (์›๊ฒฉ๋ช…) (์›๊ฒฉ ๋ธŒ๋žœ์น˜๋ช…) 

# git ์ƒํƒœ๋“ค ํ™•์ธ(์ผ๋ ฌ๋ฒˆํ˜ธ ๋“ฑ)
git log

2. ๊ฐ™์ด ์ž‘์—… 

# git ์ €์žฅ์†Œ ์ƒ์„ฑ
git init

# Remote ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์™€ ์—ฐ๊ฒฐ -> pair์˜ remote๋„ ๋™์ผํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์—ฐ๊ฒฐ
git remote add (์›๊ฒฉ๋ช…) url(Github ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์ฃผ์†Œ) 

# Remote ๋ ˆํŒŒ์ง€ํ† ๋ฆฌ์— commit ๋‚ด์—ญ ์—…๋กœ๋“œ
git push (์›๊ฒฉ๋ช…) (์›๊ฒฉ ๋ธŒ๋žœ์น˜๋ช…)
# ์ดํ›„์—๋Š” git push๋งŒ ์ž…๋ ฅํ•ด๋„ ๋จ
# Github์— ํ•ด๋‹น ์ด๋ฆ„์˜ ๋ธŒ๋žœ์น˜๊ฐ€ ์—†์„ ๋•Œ๋Š” ์ƒˆ๋กœ ์ƒ์„ฑ๋จ

# ๋ฆฌ๋ชจํŠธ ํ™•์ธ (v์˜ต์…˜ : ๋ชฉ๋ก๊ณผ ์ฃผ์†Œ๊นŒ์ง€ ํ™•์ธ)
git remote -v

# ๋‚ด commit์„ pushํ•˜๊ธฐ ์ „์— pair์˜ Remote๋ฅผ ๋‚˜์˜ local๋กœ ๋ฐ›์•„์˜ค๊ธฐ
git pull (์›๊ฒฉ๋ช…) (์›๊ฒฉ ๋ธŒ๋žœ์น˜๋ช…) 

# [์ถฉ๋Œ ํ•ด๊ฒฐํ•˜๊ธฐ : ๋ณ€๊ฒฝ ์‚ฌํ•ญ ๋‘๊ฐœ ์ค‘์— ์ทจ์‚ฌ์„ ํƒ]
console.log(‘์„ ํƒํ•  ๋ณ€๊ฒฝ์‚ฌํ•ญ’)
# ์ถฉ๋Œ์ด ํ•ด๊ฒฐ๋œ ํ›„ staging area์— ์˜ฌ๋ผ๊ฐ„ ํŒŒ์ผ์€ ์ž๋™์œผ๋กœ commit ๋ฉ”์‹œ์ง€๊ฐ€ ์ƒ์„ฑ๋จ!

3. ๋ธŒ๋žœ์น˜ 

# ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ
git branch (์ƒˆ ๋ธŒ๋žœ์น˜๋ช…)

# ์ƒˆ ๋ธŒ๋žœ์น˜ ์ƒ์„ฑ ํ›„ ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ ์ด๋™
git checkout -b (์ƒˆ ๋ธŒ๋žœ์น˜๋ช…)

# ๋ธŒ๋žœ์น˜ ๋ชฉ๋ก ์กฐํšŒ(a์˜ต์…˜ : ์›๊ฒฉ ๋ธŒ๋žœ์น˜๋ฅผ ํฌํ•จํ•˜์—ฌ ์กฐํšŒ)
git branch -a

# [๋ธŒ๋žœ์น˜๋ณ‘ํ•ฉ]
# ๋ธŒ๋žœ์น˜ ์ด๋™
git checkout (๋ธŒ๋žœ์น˜๋ช…)
git merge (๋ณ‘ํ•ฉํ•˜๋ ค๋Š” ๋ธŒ๋žœ์น˜๋ช…) 
# ๋ณ‘ํ•ฉํ•  ์ฃผ์ฒด์ธ ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ํ•˜๊ณ  ๋ณ‘ํ•ฉํ•ด์•ผํ•จ!

# ์ž„์‹œ์ €์žฅ
git stash

 


Reference