๐Ÿ“ธ Git / Github๋ž€?

Solmiiยท2020๋…„ 4์›” 27์ผ
0

Git

๋ชฉ๋ก ๋ณด๊ธฐ
1/3
post-thumbnail

Git ์ด๋ž€?
๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ [Software]
(ex : ์˜์ƒ์„ ์ดฌ์˜ํ•˜๋Š” ์นด๋ฉ”๋ผ ์–ดํ”Œ)

Github ๋ž€?
git์œผ๋กœ ์ €์žฅ๋ผ์„œ ์›๊ฒฉ ์ „์†ก๋œ ํŒŒ์ผ๋“ค์ด ์ €์žฅ๋˜๋Š” ๊ณต๊ฐ„์„ ์ œ๊ณตํ•˜๋Š” [Service]
(ex : ์œ ํŠœ๋ธŒ)

git์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์šฉ์–ด ์ •๋ฆฌ

  • Working Directory : project๋ฅผ ์ƒ์„ฑํ•ด์„œ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” ํ•˜๋“œ๋””์Šคํฌ ์ƒ์˜ ์ž‘์—… ๊ณต๊ฐ„

  • Repository : commit์ด ์ €์žฅ๋˜๋Š” ๊ณณ (์‚ฌ์ง„์ฒฉ)

  • Snapshot : ํ˜„์žฌ working directory์˜ ๋ชจ์Šต์„ ์ฐฐ์นต ์‚ฌ์ง„ ์ฐ๋“ฏ์ด ์ €์žฅ

  • Commit : snapshot์œผ๋กœ ์ €์žฅ๋œ ๋‚ด์šฉ์€ ์‚ฌ์ง„์ฒฉ์— ์‚ฌ์ง„ ์ €์žฅํ•˜๋“ฏ์ด repository์— ์ €์žฅ

  • Checkout : ์—ฌ๋Ÿฌ ์ข…๋ฅ˜์˜ checkout์ด ์žˆ๋Š”๋ฐ, ๋Œ€ํ‘œ์ ์ธ๊ฑด repository์— ์žˆ๋Š” ํŠน์ • commit์˜ ๋‚ด์šฉ์„ working directory ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ

  • Branch : ํŠน์ • dommit์— Branch ์ด๋ฆ„์„ ์ง€์ • (ํ•ด์‹œ๊ฐ’)
    โ†’ commit์„ ๊ฐ€๋ฅดํ‚ค๋Š” ๋‹จ์ˆœํ•œ ์ด๋ฆ„ํ‘œ, ๊ทธ๋ž˜๋„ ์ด ์ •๋ณด๊ฐ€ ์žˆ์œผ๋ฉด ๋ถ€๋ชจ id๋ฅผ ๋”ฐ๋ผ๊ฐ€์„œ ์ „์ฒด์ ์ธ ์ง„ํ–‰์ƒํ™ฉ์„ ์•Œ ์ˆ˜ ์žˆ์Œ


git ์—์„œ์˜ ํŒŒ์ผ์˜ ์ƒํƒœ

git์„ ์‚ฌ์šฉํ•ด์„œ ํŒŒ์ผ ๋ฒ„์ „ ๊ด€๋ฆฌ๋ฅผ ํ•  ๋•Œ, ํŒŒ์ผ์€ ๋‹ค์Œ 3๊ฐœ์˜ ์ƒํƒœ ์ค‘ ํ•˜๋‚˜์˜ ์ƒํƒœ์— ์žˆ๊ฒŒ ๋œ๋‹ค

  • Committed : ์ˆ˜์ • ์‚ฌํ•ญ๋“ค์ด git์— ์ €์žฅ๋œ ์ƒํƒœ๋ฅผ committed ์ƒํƒœ๋ผ๊ณ  ํ•˜๊ณ , ์ด๋ ‡๊ฒŒ git์— ์ €์žฅํ•˜๋Š” ํ–‰์œ„๋ฅผ Commit ํ•œ๋‹ค๊ณ  ๋งํ•œ๋‹ค.
    staging area์— ์ €์žฅ๋๋˜ ํŒŒ์ผ์ด local repository๋กœ ์ด๋™ํ•ด์„œ ์ตœ์ข… ํ™•์ •๋ณธ(commit)์ด ๋˜๋Š” ๊ฒƒ!

  • Modified : modified file์€ ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ ์ˆ˜์ •๋œ file ์ด์ง€๋งŒ, ์•„์ง committed ๋˜์ง€ ์•Š์€ ์ƒํƒœ์˜ file์„ ์˜๋ฏธํ•œ๋‹ค.

  • Staged : staged file์€ modified file์—์„œ ํ•œ๋‹จ๊ณ„ ๋” ๋‚˜์•„๊ฐ€์„œ ๊ณง commit ๋  ๊ฑฐ๋ผ๊ณ  mark๋งŒ ํ•ด๋†“์€ ์ƒํƒœ์˜ file์„ ์˜๋ฏธํ•œ๋‹ค.
    ์ฆ‰, modified ์™€ committed ์˜ ์ค‘๊ฐ„ ์ƒํƒœ์ •๋„์˜ ๋„ˆ๋‚Œ!
    modified file์„ stagingํ•˜๋ฉด index ๋ผ๋Š” ์ค€๋น„ ์˜์—ญ(staging area) ๊ณต๊ฐ„์— ์ €์žฅ๋œ๋‹ค.

Staged ๊ฐ€ ํ•„์š”ํ•œ ์ด์œ ๋Š”, commit ํ•˜๊ธฐ ์ „์— ์ค‘๊ฐ„ ์ƒํƒœ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. Commit ์„ ํ•˜๋ฉด, commit history์— ๋‚จ๊ธฐ๋„ ํ•˜๊ณ , ํ˜น์‹œ ์ถ”๊ฐ€ ์ˆ˜์ • ์‚ฌํ•ญ์ด ์ƒ๊ธฐ๋‚˜ ํ”„๋กœ์ ํŠธ ๋ฐฉํ–ฅ์ด ๋ณ€๊ฒฝ๋˜์–ด์„œ commit ์ด์ „์œผ๋กœ ๋‹ค์‹œ ๋˜๋Œ๋ ค์•ผ ํ•  ๋•Œ ๊ณผ์ •์ด ๊นŒ๋‹ค๋กœ์šด๋ฐ, Staged ๋ฅผ ์ด์šฉํ•˜๋ฉด commit ์ „์— ์ค‘๊ฐ„ ์ƒํƒœ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค.

์ฆ‰, commit์€ ํ•ด๋‹น ๊ฐœ๋ฐœ์ด ์™„์ „ํžˆ ์™„๋ฃŒ ๋์„ ๋•Œ ํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—, ์•„์ง ์™„๋ฃŒ๋Š” ์•ˆ๋˜์—ˆ์ง€๋งŒ ์ค‘๊ฐ„ ์ƒํƒœ๋ฅผ ์ €์žฅํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๋•Œ staging์„ ์‚ฌ์šฉ!!


Branch, Tag, HEAD ๊ทธ๊ฒŒ ๋ญ”๋ฐ?

working directory์—์„œ ์ž‘์—…ํ•œ ํŒŒ์ผ์„ repository์— commitํ•˜๊ฒŒ ๋˜๋ฉด...
์ด๋ ‡๊ฒŒ master(๊ธฐ๋ณธ์ด ๋˜๋Š” branch)์™€ HEAD(ํ˜„์žฌ branch,commit์ด ๋ฌด์—‡์ธ์ง€ ์•Œ๋ ค์ฃผ๋Š” pointer)๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค!
working directory์— ์ˆ˜์ • ์‚ฌํ•ญ์ด ์ƒ๊ฒจ์„œ ์ด๋ฅผ ๋‹ค์‹œ commit์„ ํ•˜๋ฉด, master์˜ ๊ฐ’์ด ๋‹ฌ๋ผ์ง„๋‹ค (HEAD๋Š” ๋™์ผ)

  • Master : ๊ฐ€์žฅ ์ตœ๊ทผ์˜ ์ปค๋ฐ‹์„ ๊ฐ€๋ฅดํ‚จ๋‹ค.
    (ํ•ด์‹œ๊ฐ’์€ ์ž๋™์œผ๋กœ ๊ฐฑ์‹ ๋œ๋‹ค)
  • Tag : ํ—ค๋“œ์™€ ๋ธŒ๋žœ์น˜์™€๋Š” ๋‹ฌ๋ฆฌ ํ•ด์‹œ๊ฐ’์ด ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค.
    (ํ•ด์‹œ๊ฐ’์„ ์ˆ˜์ •ํ•ด์•ผ ํ•  ๊ฒฝ์šฐ, ์‚ญ์ œ ํ›„ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์•ผํ•จ)
  • HEAD : ํ˜„์žฌ ๊ธฐ์ค€์ด ๋˜๋Š” commit์„ ๊ฐ€๋ฅดํ‚จ๋‹ค.
    (master = H34FC๋ผ๋Š” commit์„ ๊ฐ€๋ฅดํ‚จ๋‹ค)

Branch๋ž€, ๋…๋ฆฝ์ ์œผ๋กœ ์–ด๋–ค ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๊ฐœ๋…์ด๋‹ค.
ํ•„์š”์— ์˜ํ•ด ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฐ๊ฐ์˜ ๋ธŒ๋žœ์น˜๋Š” ๋‹ค๋ฅธ ๋ธŒ๋žœ์น˜์˜ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—, ์—ฌ๋Ÿฌ ์ž‘์—…์„ ๋™์‹œ์— ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ , ์ž‘์—…(์–ด๋–ค ๊ธฐ๋Šฅ ์ถ”๊ฐ€...ํ˜น์€ ์Šคํƒ€์ผ ์ˆ˜์ • ๋“ฑ)์ด ๋๋‚ฌ๋‹ค๋ฉด, ๋ณ‘ํ•ฉ(Merge)ํ•จ์œผ๋กœ์จ, ์ž‘์—…ํ•œ ๋‚ด์šฉ์„ ๋‹ค์‹œ ์ƒˆ๋กœ์šด ํ•˜๋‚˜์˜ ๋ธŒ๋žœ์น˜๋กœ ๋ชจ์„ ์ˆ˜ ์žˆ๋‹ค.
(๋ณดํ†ต์€ ๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—…ํ•œ ๋‚ด์šฉ์€ master์— mergeํ•˜์ง€๋งŒ, ํ”ผ์š”ํ•˜๋‹ค๋ฉด ๋ธŒ๋žœ์น˜์™€ ๋ธŒ๋žœ์น˜๋ผ๋ฆฌ๊ณ  merge ํ•  ์ˆ˜ ์žˆ๋‹ค.)

์œ„ ๊ทธ๋ฆผ์„ ๋ณด๋ฉด ์ดˆ๋ก์ƒ‰ master์—์„œ ๊ธฐ๋Šฅ๋ณ„๋กœ ์ถ”๊ฐ€๋œ ๋‹ค์–‘ํ•œ ๋ธŒ๋žœ์น˜๋“ค์ด ๊ฐ์ž์˜ ๊ธฐ๋Šฅ ๊ตฌํ˜„์ด ๋๋‚œ ํ›„์— ๋‹ค์‹œ master์— merge๋˜์–ด ๊ฒฐ๊ตญ, ํ•˜๋‚˜์˜ master๋งŒ ๋‚จ๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

master์— mergeํ•œ ๋ธŒ๋žœ์น˜๋Š” ์žฌ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค!


git ์ดˆ๊ธฐ ์„ค์ •ํ•˜๊ธฐ

(0) cdํด๋”๊ฒฝ๋กœ : git ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค ๊ฒฝ๋กœ๋กœ ์ด๋™

(1 - 1) git init
์ƒˆ๋กœ์šด Local ์ €์žฅ์†Œ ๋งŒ๋“ค๊ธฐ (.git ํด๋”)
ํ”„๋กœ์ ํŠธ๋ฅผ git repository๋กœ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด
(ํ”„๋กœ์ ํŠธ = ๊ฐœ๋ฐœํ•˜๊ณ ์ž ํ•˜๋Š” ์†Œ์Šค์ฝ”๋“œ๋“ค์ด ์žˆ๋Š” ๋””๋ ‰ํ† ๋ฆฌ)

(1 - 2) git clone/๋กœ์ปฌ/์ €์žฅ์†Œ/๊ฒฝ๋กœ
gthun์—์„œ ๋งŒ๋“  ์ €์žฅ์†Œ๋ฅผ github์˜ url์„ ํ†ตํ•ด Local๋กœ ๋ณต์‚ฌํ•˜๊ธฐ

(2) git remote add origin repository address
git clone ์œผ๋กœ ๊ธฐ์กด ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๋ณต์ œํ–ˆ์œผ๋ฉด skip,
์•„๋‹ˆ๋ผ๋ฉด ํ˜„์žฌ ์›๊ฒฉ ์„œ๋ฒ„์˜ ์ฃผ์†Œ๋ฅผ git์—๊ฒŒ ์•Œ๋ ค์ค˜์•ผ ํ•œ๋‹ค.

(3) git config --global user.name "user name"

(4) git config --global user.email "user e-mail"

์ž์„ธํ•œ ์„ค์ •๋ฒ•์€ ์œ ํŠœ๋ธŒ ์ฐธ๊ณ 


๐Ÿ•น Bonus! Git Branch์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•  ์ˆ˜ ์žˆ๋Š” ์‚ฌ์ดํŠธ!

profile
ํ•˜๋ฃจ๋Š” ์น˜์—ดํ•˜๊ฒŒ ์ธ์ƒ์€ ์—ฌ์œ ๋กญ๊ฒŒ

0๊ฐœ์˜ ๋Œ“๊ธ€