๐Ÿ”ง Git: ์Šคํ† ๋ฆฌ๋ถ

2369 ๋‹จ์–ด gitgithub
ํž˜๋‚ด ์น˜ํŠธ ์‹œํŠธ

์†Œ๊ฐœ

Git์€ ๊ธฐ์—… ๋‚ด ํŒ€์„ ํ†ตํ•œ ํ˜‘์—…์„ ์ง€์›ํ•˜๋Š” ๋ถ„์‚ฐ ๋ฒ„์ „ ๊ด€๋ฆฌ ์‹œ์Šคํ…œ์ž…๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž ํŒ€๊ณผ ์˜คํ”ˆ ์†Œ์Šค ์†Œํ”„ํŠธ์›จ์–ด ์œ ์ง€ ๊ด€๋ฆฌ์ž๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ Git์„ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž ๋ฐ DevOps ์—”์ง€๋‹ˆ์–ด๋ฅผ ์œ„ํ•œ ์˜คํ”ˆ ์†Œ์Šค ์†Œํ”„ํŠธ์›จ์–ด ํˆดํ‚ท์œผ๋กœ ๋งค์šฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

Git์€ ๊ณต์‹ ์›น์‚ฌ์ดํŠธ์—์„œ ๋‹ค์šด๋กœ๋“œํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด ์žˆ์œผ๋ฉฐ Linux, MacOS ๋ฐ Windows์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Git ์„ค์ •

๋‹ค์Œ ๋ช…๋ น์–ด๋กœ Git ๋ฒ„์ „์„ ํ™•์ธํ•˜์„ธ์š”.

git --version


๋‹ค์Œ ๋ช…๋ น์–ด๋กœ ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ Git ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

git init


GitHub ๋˜๋Š” GitLab ์ธ์Šคํ„ด์Šค์—์„œ ์ง€์ •๋œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ URL ๋˜๋Š” ์„œ๋ฒ„ ์œ„์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›๊ฒฉ์œผ๋กœ ํ˜ธ์ŠคํŒ…๋˜๋Š” Git ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ณต์ œํ•ฉ๋‹ˆ๋‹ค.

git clone https://www.github.com/username/repo-name


ํ˜„์žฌ Git ๋””๋ ‰ํ† ๋ฆฌ์˜ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

git remote


๊ฐ์ƒ‰

์Šคํ…Œ์ด์ง•๋˜์ง€ ์•Š์€ ์ถ”๊ฐ€๋œ ํŒŒ์ผ๊ณผ ์Šคํ…Œ์ด์ง•๋œ ํŒŒ์ผ๋„ ํฌํ•จํ•˜์—ฌ Git ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

git status


ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ํŒŒ์ผ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

git add .


์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์˜ ์Šคํ…Œ์ด์ง•์—์„œ ํŒŒ์ผ์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

git reset CDI.java


์ปค๋ฐ‹

๋‚˜์ค‘์— ์ปค๋ฐ‹์„ ์ถ”์ ํ•  ์ˆ˜ ์žˆ๋Š” ์˜๋ฏธ ์žˆ๋Š” ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€์™€ ํ•จ๊ป˜ ์ค€๋น„๋œ ํŒŒ์ผ์„ ์ปค๋ฐ‹ํ•ฉ๋‹ˆ๋‹ค.

git commit -m "Added new files"


์ง€์ 

๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ํ˜„์žฌ ๋ถ„๊ธฐ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

git branch


์ž‘์—… ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์ƒˆ ๋ถ„๊ธฐ๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

git branch new-branch


๋‹ค๋ฅธ ๊ธฐ์กด ๋ถ„๊ธฐ๋กœ ์ „ํ™˜ํ•˜๊ณ  ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ฒดํฌ์•„์›ƒํ•ฉ๋‹ˆ๋‹ค.

git checkout another-branch


๋ถ„๊ธฐ๋ฅผ ๋งŒ๋“ค๊ณ  ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ์˜ ์ƒˆ ๋ถ„๊ธฐ๋กœ ์ „ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

git checkout -b new-branch


ํŠน์ • ๋ธŒ๋žœ์น˜์˜ ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ํ˜„์žฌ ๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉํ•ฉ๋‹ˆ๋‹ค.

git merge branch-name


ํ˜‘์—… ๋ฐ ์—…๋ฐ์ดํŠธ

์ถ”์  ์›๊ฒฉ ๋ถ„๊ธฐ์—์„œ ์ปค๋ฐ‹์„ ๊ฐ€์ ธ์™€ ๋ณ‘ํ•ฉํ•ฉ๋‹ˆ๋‹ค.

git pull


๋กœ์ปฌ ๋ธŒ๋žœ์น˜๋ฅผ ์›๊ฒฉ ์ €์žฅ์†Œ ๋ธŒ๋žœ์น˜๋กœ ํ‘ธ์‹œํ•ฉ๋‹ˆ๋‹ค.

git push origin main


๊ฒ€์‚ฌ

ํ˜„์žฌ ํ™œ์„ฑ ๋ธŒ๋žœ์น˜์— ๋Œ€ํ•œ ์ปค๋ฐ‹ ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

git log

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ