๐Ÿ“˜ Git & Git Hub

[meษช]ยท2021๋…„ 8์›” 17์ผ
1

3. Today I Learned. Basic

๋ชฉ๋ก ๋ณด๊ธฐ
2/11

Preface

๐Ÿ“Œ ๊ฐœ๋ฐœ ๊ณต๋ถ€ 1๊ฐœ์›” ์ฐจ์ธ to-be ๊ฐœ๋ฐœ์ž์˜ ์ž์Šต ๋ธ”๋กœ๊ทธ๐Ÿ™‚๏พ Aug 15 ~ 21, 2021

ํ˜„์žฌ ์ƒํƒœ
๋ฉ˜๋ถ•์˜ ์—ฐ์†. terminal ํ™”๋ฉด์ด๋ž‘ ๋ช…๋ น์–ด๋„ ์•„์ง ์•ˆ ์ต์ˆ™ํ•œ๋ฐ Git ๋ช…๋ น์–ด๋กœ ์ž‘์—…๋ฌผ์„ ๊ด€๋ฆฌํ•ด์•ผ ํ•˜๋‹ค๋‹ˆ...
์ง€๊ธˆ์€ ๊ฐœ์ธ ์ž‘์—…๋ฌผ์ด์ง€๋งŒ ๋จธ์ง€ ์•Š์•„ team project๋ฅผ ํ•˜๊ฒŒ ๋  ํ…๋ฐ ์ด๋•Œ ์ ˆ๋Œ€ ์‹ค์ˆ˜ํ•˜๋ฉด ์•ˆ ๋œ๋‹ค......ใ…œvใ…œ

Git & Git Hub

โž• afterthought

์ด ์—ญ์‹œ ์†์— ์ต์œผ๋ฉด ๋ณ„ ๊ฒŒ ์•„๋‹ˆ๊ฒŒ ๋  ๊ฒƒ์ด๋„๋‹ค... ๋ˆ„๊ฐ€ ๋„ˆ๋”๋ผ ํ•ด์ปค ํ•˜๋ผ๋Š” ๊ฑฐ ์•„๋‹ˆ์ž–์•„. ๊ธฐ์šด๋‚ด๋ผ ์งœ์‹์•„
๋„์™€์ฃผ์‹  ๋ถ„๋“ค ์—†์—ˆ์œผ๋ฉด ๋‚œ ์–ด๋–ป๊ฒŒ ๋์„๊นŒ.

1. intro

Git์€ VCS(Version Control System)์„ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ์ฃผ์š”ํ•œ tool์ด๋‹ค.
push๋งŒ ์ž˜ ํ•ด๋‘์—ˆ๋‹ค๋ฉด ์ž‘์—…๋ฌผ์„ ์›ํ•˜๋Š” ์ˆœ๊ฐ„์œผ๋กœ ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.

centalized version control์ด ์•„๋‹ˆ๋ผ distributed version control์ด๊ธฐ ๋•Œ๋ฌธ์— ์ž‘์—…์ž๋“ค์ด server ์•ˆ์ •์„ฑ์˜ ์˜ํ–ฅ์„ ๋œ ๋ฐ›์œผ๋ฉด์„œ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ๊ณ , offline์—์„œ๋„ ์ž‘์—…ํ•  ์ˆ˜ ์žˆ๋‹ค.
์–ด์จŒ๋“  ์ž‘์—…๋ฌผ์€ server์— ๋ณด๊ด€๋˜๋Š”๋ฐ, ๋Œ€ํ‘œ์ ์ธ server๊ฐ€ Git Hub์ด๋‹ค.
Git์œผ๋กœ ๊ด€๋ฆฌํ•œ ์ž‘์—…๋ฌผ์„ Git Hub์— ์˜ฌ๋ฆฌ๊ณ  ํ˜‘์—… ๊ด€๊ณ„์ž์™€ ์†Œํ†ตํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋ฅผ ์š”์•ฝํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • Git watches my files all the time and keeps my records.
  • Git allows me to keep alternative versions of the same file.
  • Git allows me to work with other people on the same file.
  • Git Hub is a Git provider in the cloud. I and my co workers can sync our gits into Git Hub.
  • There is a lot of open source project from Amazon, Facebook, Airbnb, etc
    โ€ป git hub โ‰’ gitlab โ‰’ bitbucket

Git์€ ๋ช…๋ น์–ด๋ฅผ ๊ธฐ๋ณธ์œผ๋กœ ํ•œ '๋ช…๋ น์–ด program'์ด๋ฉฐ ๋ช…๋ น์–ด๋Š” git + ๋ช…๋ น์–ด + ์†์„ฑ์œผ๋กœ ์ž‘์„ฑํ•œ๋‹ค.
Git ๊ณต์‹ homepage์—์„œ documentation ํ•˜์œ„์— ์žˆ๋Š” 'Reference' menu์— ๋ช…๋ น์–ด์™€ ์†์„ฑ ๊ฐ’์ด ์ •๋ฆฌ๋˜์–ด ์žˆ๋‹ค.
terminal์—์„œ git ๋ช…๋ น์–ด + --h๋ฅผ ์ž…๋ ฅํ•ด๋„ ๋ช…๋ น์–ด์˜ ์†์„ฑ ๊ฐ’์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

Git์˜ GUI pgrogram์œผ๋กœ SourceTree๋‚˜ GitKraken์„ ์“ฐ๊ธฐ๋„ ํ•œ๋‹ค. (๋‚˜๋Š” Fork!)

Git Hub์—์„œ open source๋ฅผ ์ฐธ๊ณ ํ•˜๊ธฐ๋„ ํ•˜๊ณ , ๊ฐ„๋‹จํ•œ ์˜คํƒ€ ์ˆ˜์ •๋ถ€ํ„ฐ (ํ”ํžˆ '์ด์‚ญ์ค๊ธฐ') ๋ฒˆ์—ญ ํ˜น์€ ์˜ค๋ฅ˜ ๊ฐœ์„  ๋“ฑ ๋‚ด๊ฐ€ ์ฐธ์—ฌํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
์œ ๋ช…ํ•œ open source๋Š” PR์„ ํ•  ๋•Œ template์ด ์žˆ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค.


2. setup

๏พ ๏พ 1) terminal์—์„œ git --version์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ version์ด ๋‚˜์˜ค๋ฉด ์ด๋ฏธ Git์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š” ๊ฒƒ
๏พ ๏พ ๏พ ๏พ ๋งŒ์•ฝ ์—†๋‹ค๋ฉด ๊ณต์‹ homepage์—์„œ download
๏พ ๏พ 2) Git์„ ์„ค์น˜ํ•˜๋ฉด Git์— ๋Œ€ํ•œ ๋ชจ๋“  ํ™˜๊ฒฝ ์„ค์ •์ด .gitconfig file ์•ˆ์— ์ €์žฅ๋˜๋ฏ€๋กœ terminal์—์„œ git config --list๋ผ๊ณ  ์ž…๋ ฅํ•˜๋ฉด Git์˜ ๋ชจ๋“  ์„ค์ • ํ™•์ธ ๊ฐ€๋Šฅ
๏พ ๏พ 3) editor์—์„œ ์ค„๋ฐ”๊ฟˆ์„ ํ•  ๋•Œ ์šด์˜์ฒด์ œ์— ๋”ฐ๋ผ ํ˜ธํ™˜์ด ๋˜์ง€ ์•Š์•„ git history๋‚˜ git blame ๋ช…๋ น์–ด์—์„œ ๋ฌธ์ œ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋ฏ€๋กœ git config --global core.autocrlf input ์ž…๋ ฅ
๏พ ๏พ 4) git init์œผ๋กœ Git ์ดˆ๊ธฐํ™” / ์‹œ์ž‘
๏พ ๏พ ๏พ ๏พ Git์„ ์ดˆ๊ธฐํ™”ํ•˜๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ master branch๊ฐ€ ์ƒ์„ฑ๋จ
๏พ ๏พ ๏พ ๏พ master branch๊ฐ€ commitํ•œ ๊ฑธ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ž„
๏พ ๏พ 5) project directory์—์„œ ls -al ํ•˜๋ฉด '.git'์ด ๋‚˜์˜ค๋Š”๋ฐ ์ด๋Š” Git์ด ํ•ด๋‹น project๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ด๊ณ , .git์€ ์ˆจ๊ฒจ์ง„ file์ž„
๏พ ๏พ ๏พ ๏พ ls๋ผ๊ณ ๋งŒ ํ•˜๋ฉด ์ˆจ๊ฒจ์ง„ file์€ ๋‚˜์˜ค์ง€ ์•Š์Œ
๏พ ๏พ 6) rm -rf .git ํ•˜๋ฉด Git์ด ์‚ญ์ œ๋˜์–ด์„œ ๋” ์ด์ƒ Git project๊ฐ€ ์•„๋‹ˆ๊ฒŒ ๋จ
๏พ ๏พ 7) ํ˜„์žฌ file์˜ ์ƒํƒœ๊ฐ€ ๊ถ๊ธˆํ•˜๋ฉด git status


3. workflow

  • summary

    • working directory
      : ๋‚ด๊ฐ€ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” file
      • git init
      • git commit -m "first commit"
      • git branch -M main
      • git remote add origin https๋กœ_์‹œ์ž‘ํ•˜๋Š”_git_์ €์žฅ์†Œ_์ฃผ์†Œ
      • git push -u origin main
  • local

    • working directory
      : ๋‚ด๊ฐ€ ์ž‘์—…ํ•˜๊ณ  ์žˆ๋Š” file
      • untracked : git init์„ ์•ˆ ํ•ด์„œ Git์ด trackํ•˜๊ณ  ์žˆ์ง€ ์•Š๋Š” ์ž๋ฃŒ
      • traked : Git์ด trackํ•˜๊ณ  ์žˆ์Œ
        • unmodified : ์ด์ „ version ์ดํ›„ ์ˆ˜์ • ์ด๋ ฅ์ด ์—†๋Š” file์ด์–ด์„œ staging area๋กœ ์ด๋™๋  ์ˆ˜ ์—†์Œ
        • modified : ์ด์ „ version ์ดํ›„ ์ˆ˜์ • ์ด๋ ฅ์ด ์žˆ๋Š” file์ด๋ฉฐ, ์ด๋Ÿฐ file๋งŒ staging area๋กœ ์ด๋™๋  ์ˆ˜ ์žˆ์Œ (git add . ํ˜น์€ git add file๋ช….ํ™•์žฅ์ž๋ฅผ ์ž…๋ ฅํ•ด staging area๋กœ ์ด๋™)
          • git add *๋Š” ๋ชจ๋“  file์„ staging area๋กœ ์˜ฎ๊ธฐ๋Š” ๋ช…๋ น์–ด์ธ๋ฐ, ๋งŒ์•ฝ ์ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ธฐ ์ „์— ์ˆ˜์ • ์ด๋ ฅ์ด ์žˆ๋Š” file์„ ์‚ญ์ œํ•˜๋ฉด git add *๋ฅผ ์ž…๋ ฅํ•ด๋„ ์ˆ˜์ • ์ด๋ ฅ์ด ์žˆ๋Š” ๋‚˜๋จธ์ง€ file๋“ค์ด staging area๋กœ ์˜ฎ๊ฒจ๊ฐ€์ง€ ์•Š์Œ. ์ด๋•Œ git add .๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์‚ญ์ œ๋˜์ง€ ์•Š์€ ๋‚˜๋จธ์ง€ file๋“ค์ด staging area๋กœ ์ด๋™๋จ
          • ๋ณ€๋™ ์‚ฌํ•ญ์ด ์žˆ์–ด๋„ staging area๋กœ ์˜ฎ๊ธฐ๊ณ  ์‹ถ์ง€ ์•Š๋‹ค๋ฉด, echo file๋ช….ํ™•์žฅ์ž > .gitignore ๋ช…๋ น์–ด๋กœ ํ•ด๋‹น file์„ .gitignore file์— ์ถ”๊ฐ€ํ•˜๋ฉด ๋จ
            โ€ป create-react-app์„ ์„ค์น˜ํ•˜๋ฉด .gitignore file์ด ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๋ฉฐ, ์ด ์•ˆ์— ๊ธฐ์žฌ๋˜์–ด ์žˆ๋Š” ๋‚ด์šฉ์€ Git์ด trackํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋Š” ์žฅ์น˜์ž„
          • ์–ด๋–ค file์˜ ๋‚ด์šฉ์ด ์–ด๋–ป๊ฒŒ ์ˆ˜์ •๋˜์—ˆ๋Š”์ง€ ์•Œ๊ณ  ์‹ถ๋‹ค๋ฉด git diff ์ž…๋ ฅ, ๊ทธ ์ค‘์—์„œ๋„ staging area์— ์žˆ๋Š” ๋‚ด์šฉ๋งŒ ๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด git diff --staged ํ˜น์€ git diff --cached ์ž…๋ ฅ
          • git diff --staged ๋ช…๋ น์–ด๋Š” ๋ณ€๊ฒฝ ๋‚ด์—ญ์„ terminal์—์„œ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด ๋‚ด์šฉ์„ editor์—์„œ ๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด git config --global -e์„ ์ž…๋ ฅํ•ด์„œ [diff] tool = vscode [difftool "vscode"] cmd = code --wait --diff $LOCAL $REMOTE๋ฅผ ์ž‘์„ฑํ•œ ํ›„ ์ €์žฅ, ๋‹ค์‹œ terminal์—์„œ git diftool ํ˜น์€ git difftool --staged ์ž…๋ ฅ
    • staging area
      : ์–ด๋Š ์ •๋„ ์ž‘์—…ํ•˜๋‹ค๊ฐ€ version history์— ์ €์žฅํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด ์žˆ์–ด์„œ file๋“ค์„ ์˜ฎ๊ฒจ๋†“๋Š” ๊ณณ
      • git add๋กœ staging area๋กœ ์ด๋™
        • ํ•œ ์ค„, ํ•œ ์ค„์”ฉ staging area๋กœ ์ด๋™์‹œํ‚ฌ ์ˆ˜๋„ ์žˆ์Œ
      • git rm --cached file๋ช….ํ™•์žฅ์ž๋กœ ๋‹ค์‹œ working direcotry๋กœ ์ด๋™
      • git commit์€ commit ๋ช…๋ น์–ด์ธ๋ฐ ์ด๊ฒƒ๋ณด๋‹ค๋Š” git commit -m "commit message"๋ฅผ ๋” ๋งŽ์ด ์‚ฌ์šฉ
      • ๋ชจ๋“  ์ž‘์—…๋ฌผ์„ ํ•œ ๋ฒˆ์— commitํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด git commit -am "commit message"
      • commit ๋‚ด์—ญ์„ ๋ณด๊ณ  ์‹ถ๋‹ค๋ฉด git log
        โ€ป Git ์ „๋ฐ˜์— ํ•ด๋‹น๋˜๋Š” ๋‚ด์šฉ์ด์ง€๋งŒ, ํŠนํžˆ commit message๋Š” ์กฐ์ง๋งˆ๋‹ค์˜ convention์ด ์žˆ์œผ๋‹ˆ ๊ทธ ๊ทœ์น™์„ ๋”ฐ๋ฅผ ๊ฒƒ
    • .git directory (ํ˜น์€ .git repository)
      : version์˜ history๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ
      ๏พ commit์œผ๋กœ ์ƒˆ version์„ ๋งŒ๋“ค์–ด .git directory์— ์˜ฌ๋ฆฌ๊ณ , checkout์œผ๋กœ ์›ํ•˜๋Š” version์œผ๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ์Œ
      • verison์— ๋‹ด๊ฒจ์žˆ๋Š” ์ •๋ณด
        • ๊ฐ๊ฐ์˜ commit์—” snapshot๋œ ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ณ ์œ ํ•œ hash code๊ฐ€ ๋ถ€์—ฌ๋˜๋Š”๋ฐ, ์ด๋ฅผ ํ†ตํ•ด version ๊ด€๋ฆฌ ๊ฐ€๋Šฅ
          • ๋ณ€๊ฒฝ ์‚ฌํ•ญ๋งŒ ์ €์žฅํ•˜๋Š” delta base๊ฐ€ ์•„๋‹ˆ๋ผ project ์ „์ฒด๋ฅผ ์ €์žฅํ•˜๋Š” snapshot์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ version์˜ project๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ž„
        • commit์—๋Š” message๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ˆ„๊ฐ€ ์–ธ์ œ commit ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ–ˆ๋Š”์ง€ ๊ธฐ๋ก๋˜์–ด ์žˆ์Œ
      • commit๋“ค์€ ์ผ์ข…์˜ history ์ฐฝ๊ณ ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋„ˆ๋ฌด ํฐ ๋ณ€๋™ ์‚ฌํ•ญ์„ ํ•œ ๋ฒˆ์— commitํ•˜๋Š” ๊ฒƒ๋„, ๋„ˆ๋ฌด ์‚ฌ์†Œํ•œ ๋ณ€๋™ ์‚ฌํ•ญ์„ ์ž์ฃผ commitํ•˜๋Š” ๊ฒƒ๋„ ์ง€์–‘ํ•˜๊ณ  Git ์‚ฌ์šฉ ๋ชฉ์ ์— ๋ถ€ํ•ฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ์˜๋ฏธ ์žˆ๋Š” ์ž‘์€ ๋‹จ์œ„๋ฅผ commitํ•ด์•ผ ํ•จ
      • commit message์— ์‚ฌ์šฉ๋˜๋Š” Init, Add, Fix ๋“ฑ์˜ ์–‘์‹์€ ํ˜„์žฌํ˜•์œผ๋กœ ์ž‘์„ฑ
      • commitํ•  ๋• commit message์— ํ•ด๋‹นํ•˜๋Š” ๋‚ด์šฉ๋งŒ ๋‹ด์•„์•ผ์ง€, commitํ•˜๋Š” ๊น€์— ๋‹ค๋ฅธ ์ž‘์—…๋„ ํฌํ•จํ•ด๋ฒ„๋ฆฌ๋ฉด reviewํ•  ๋•Œ ํ˜ผ์„ ์ด ์˜ค๊ธฐ๋„ ํ•˜๊ณ  history ๊ด€๋ฆฌ๋„ ์–ด๋ ค์›€
  • remote

    • push๋กœ remote์— ๋ณด๋ƒ„
    • pull๋กœ remote์— ์žˆ๋Š” ๊ฑฐ ๋ฐ›์•„์˜ด

๊ฒฐ๊ตญ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ Git์„ ์‚ฌ์šฉํ•ด ์ž‘์—…๋ฌผ์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

  • mostly common used
  • free
  • open source
  • lightning fast
  • work offline
  • undo mistakes
  • easy and fast branching/merging

4. git flow

1) git clone

pwd // ํ˜„์žฌ ์œ„์น˜ ํ™•์ธ
cd desktop
cd <project folder> // folder๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ์œผ๋ฉด mkdir <folder๋ช…>
git init // ์ด ์œ„์น˜์—์„œ git์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ดˆ๊ธฐํ™”/์‹œ์ž‘
git status // ํ˜„์žฌ ์ƒํƒœ ํ™•์ธ
git clone <Git ์ฃผ์†Œ> // ํ˜น์€ git remote add origin <Git ์ฃผ์†Œ>๋กœ ์›๊ฒฉ ์ €์žฅ์†Œ ์ถ”๊ฐ€
// git clone์€ remote์˜ code๊ฐ€ local์ธ ๋‚˜์—๊ฒŒ ๋“ค์–ด์˜จ ๊ฒƒ
ls // directory์™€ file ํ™•์ธ
cd <merge๋ฐ›์€ directory ์ด๋ฆ„> // file์„ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด touch <file๋ช….ํ™•์žฅ์ž>
.code // ๋‹ค๋ฅธ terminal์—์„œ code ์ž…๋ ฅํ•˜๊ณ  ์žˆ์—ˆ์œผ๋ฉด ์ด ๋ช…๋ น์–ด๋กœ editor๋กœ ์ด๋™, 'cmd + J'๋กœ editor์˜ terminal tab ์—ด๊ธฐ
npm install
// master๋ฅผ main์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด git branch -m master main
git branch // branch ์ƒํƒœ ํ™•์ธ
git branch <feature/๋‚ด๊ฐ€์ž‘์—…์ค‘์ธ๊ธฐ๋Šฅ> // branch ์ƒ์„ฑ ex. feature/login
// branch๊ฐ€ ํŠน์ • ์‹œ์ ๋ถ€ํ„ฐ ์ƒˆ๋กœ์šด ์‹œ๊ณต๊ฐ„์ด ๋งŒ๋“ค์–ด์ ธ์„œ (like ํ‰ํ–‰ ์šฐ์ฃผ) ๊ฐ์ž์˜ ์ž‘์—…์ด ์„œ๋กœ์—๊ฒŒ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์œผ๋ฉฐ, <feature/๋‚ด๊ฐ€์ž‘์—…์ค‘์ธ๊ธฐ๋Šฅ>์€ ์ž‘์—…์ž๋ผ๋ฆฌ ์•ฝ์†ํ•œ ์ด๋ฆ„์ž„
// โ€ป ๋‹ค๋ฅธ ๊ธฐ๋Šฅ ์ž‘์—…ํ•  ๊ฑฐ๋ฉด git checkout main ํ›„ git branch <feature/์ž‘์—…ํ• ๊ธฐ๋Šฅ>์œผ๋กœ branch ์ด๋™ ๋ฐ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์„ ํ–‰๋˜์–ด์•ผ ํ•จ

clone ๋ฐ›์€ ํ›„ ๋ชจ๋“  ์ž‘์—…์€ brnach๋ฅผ ์ƒ์„ฑํ•ด์„œ ๊ทธ ์œ„์น˜๋กœ ์ด๋™ํ•˜์—ฌ ์ง„ํ–‰ํ•ด์•ผ ํ•œ๋‹ค.
main์—์„œ ํ•˜๋ฉด ์•ˆ ๋œ๋‹ค.


2) git push

pushํ•˜๊ธฐ ์ „์— ํ˜„์žฌ ์œ„์น˜๋ฅผ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค. main (master) branch์—์„œ๋Š” ์ž‘์—…๋„ ํ•˜๋ฉด ์•ˆ ๋˜์ง€๋งŒ push๋Š” ๋” ํ•˜๋ฉด ์•ˆ ๋œ๋‹ค.

git add . // ํŠน์ • ํŒŒ์ผ์„ stagingํ•˜๊ธฐ ์›ํ•œ๋‹ค๋ฉด git add <file๋ช….ํ™•์žฅ์ž>.
// git commit์€ commit message๊ฐ€ ์—ฌ๋Ÿฌ ์ค„์ผ ๋•Œ ์‚ฌ์šฉํ•˜๊ณ  ๋ณดํ†ต์€ ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋กœ commitํ•จ
git commit -m "<commit meassage>"
git push origin <feature/๊ฐœ๋ฐœ์ค‘์ธ๊ธฐ๋Šฅ>
git log // commit ํ˜„ํ™ฉ ํ™•์ธ

commit์„ ์—ฌ๋Ÿฌ ์ค„ ์“ฐ๊ณ  ์‹ถ๋‹ค๋ฉด vi ํ•˜๊ณ  i ๋ˆŒ๋Ÿฌ์„œ ์ž‘์„ฑ โ†’ ESC โ†’ :wq๋กœ commit message๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ฐ–์œผ๋กœ ๋‚˜์˜จ๋‹ค.
commit ์ž‘์„ฑ ์–‘์‹์€ ์กฐ์ง์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋‹ค.

๋ถ„๋ฅ˜ : ํ•œ์ค„ ์ œ๋ชฉ
- ๊ตฌํ˜„ ๋‚ด์šฉ ์ƒ์„ธ ์„ค๋ช… 1
- ๊ตฌํ˜„ ๋‚ด์šฉ ์ƒ์„ธ ์„ค๋ช… 2
  • Add : layout์ด๋‚˜ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
  • Remove : ๋‚ด์šฉ ์‚ญ์ œ (folder๋‚˜ file ์‚ญ์ œ)
  • Modify : ์ˆ˜์ • ex. JSON data์˜ format ๋ณ€๊ฒฝ, button ์ƒ‰๊น” ๋ณ€๊ฒฝ, font ๋ณ€๊ฒฝ ๋“ฑ)
  • Fix : bug/์˜ค๋ฅ˜ ํ•ด๊ฒฐ
  • Refactor : code refactoring (review ๋ฐ˜์˜, ์Šค์Šค๋กœ refactoring, ์ค‘๋ณต/๋ถˆํ•„์š”ํ•œ code ์ œ๊ฑฐ, ์„ฑ๋Šฅ ๊ฐœ์„  ๋“ฑ)
  • Docs : ๋ฌธ์„œ์— ๊ด€๋ จ๋œ ์ˆ˜์ • ์ž‘์—… (README.md ๋“ฑ)

3) pull request

"remote์˜ master(main) branch์•ผ, ๋‚˜ ์ค€๋น„๋ผ์„œ merge ์š”์ฒญํ–ˆ์œผ๋‹ˆ๊นŒ ๋‹น๊ฒจ์ค˜."์˜ ์˜๋ฏธ์ด๋‹ค.
Git Hub์—์„œ PR์„ ์ž‘์„ฑํ•˜๋ฉด ๋˜๋Š”๋ฐ, ์ด๋•Œ convention์„ ์ค€์ˆ˜ํ•ด์•ผ ํ•œ๋‹ค.


4) git pull

์ง€๊ธˆ๊นŒ์ง€ ํ•œ ๊ฑฐ commitํ•˜๊ณ , remote main์—์„œ merge๋œ ๊ฑฐ pull ๋ฐ›๊ณ , local์—์„œ๋„ merge๋ฅผ ํ•ด์•ผ team ์ž‘์—…๋ฌผ์„ ์ตœ์‹ ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.
conflict ํ•ด๊ฒฐ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€ ๊ณผ์ •์ด๋‹ค.

git checkout main
git pull origin main
git checkout feature/์ž‘์—…์ค‘์ธ๊ธฐ๋Šฅ
git merge main
git add .
git commit -m "Fix: conflict ํ•ด๊ฒฐ"
git push origin feature/์ž‘์—…์ค‘์ธ๊ธฐ๋Šฅ

main์ด ๋งŽ์ด ์ง„ํ–‰๋œ ์ƒํƒœ์—์„œ branch๊ฐ€ ๋„ˆ๋ฌด ์˜ˆ์ „ ์ƒํƒœ์ด๋ฉด conflict ์ƒ๊ธฐ๋‹ˆ๊นŒ main์„ ๋จผ์ € pull ๋ฐ›๊ณ  branch๋ฅผ pushํ•˜๋Š” ๊ฒŒ conflict๊ฐ€ ๋œ ์ƒ๊ธด๋‹ค.
merge ํ›„์—” ๋‚ด๊ฐ€ ํ•˜๋˜ ์ž‘์—…๋ฌผ์„ ์‚ญ์ œํ•ด๋„ ๋œ๋‹ค.

git log --graph --all --decorate๋กœ merge ํ˜„ํ™ฉ์„ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.




Endnote

git - Book
์–„ํŒํ•œ ์ฝ”๋”ฉ์‚ฌ์ „ - ๊ฐ€์žฅ ์‰ฌ์šด Git ๊ฐ•์ขŒ - (์ƒ) ํ˜ผ์ž์ž‘์—…ํŽธ
์–„ํŒํ•œ ์ฝ”๋”ฉ์‚ฌ์ „ - ๊ฐ€์žฅ ์‰ฌ์šด Git ๊ฐ•์ขŒ - (ํ•˜) GithubํŽธ
์ƒํ™œ์ฝ”๋”ฉ - Github.com
๐Ÿ“ Git Rebase


๐Ÿ™‡ the source of this content

๋“œ๋ฆผ์ฝ”๋”ฉ by ์—˜๋ฆฌ - ๊นƒ, ๊นƒํ—ˆ๋ธŒ ์ œ๋Œ€๋กœ ๋ฐฐ์šฐ๊ธฐ (๊ธฐ๋ณธ ๋งˆ์Šคํ„ฐํŽธ, ์‹ค๋ฌด์—์„œ ๊ฟ€๋ฆฌ์ง€ ๋ง์ž)
๋…ธ๋งˆ๋“œ ์ฝ”๋” Nomad Coders - ๊นƒ. ๊นƒํ—ˆ๋ธŒ. ๊ธฐ์ดˆ๊ฐœ๋… ์žก์•„๋“œ๋ฆผ. 5๋ถ„ ์ˆœ์‚ญ.

WeCode

profile
๋Š๋ ค๋„ ํ•  ๊ฑฐ์•ผ.......

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