๐Ÿ˜ข ์Šคํ„ฐ๋””๋…ธํŠธ(Git 3~5)

zoeยท2023๋…„ 4์›” 24์ผ
0

Git Global Configuration

  • Global Uername & Email
git config --global user.name <username>
git config --global user.email <email>

  • ์˜ˆ์ œ (Git) Global Username & Email
git config --global user.name <username>
git config --global user.email <email>




  • CRLF - Windows : ๊ฐ€์ ธ์˜ฌ ๋•Œ๋Š” LF๋ฅผ CRLF๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ๋ณด๋‚ผ ๋•Œ๋Š” CRLF๋ฅผ LF๋กœ ๋ณ€๊ฒฝ
git config --global core.autocrlf true
  • CRLF - Mac : Mac - LF๋งŒ ์‚ฌ์šฉ
git config --global core.autocrlf input
  • Line ending
    - Windows : CR(\r) + LF(\n)
    - Unix or Mac : LF(\n)
    - Windows ์‚ฌ์šฉ์ž์™€ Mac ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ™์€ Git Repository๋ฅผ ์ž‘์—…ํ•  ๋•Œ ์ฝ”๋“œ์—์„œ ๋ณ€๊ฒฝ๋œ ๋‚ด์šฉ์ด ์—†์–ด๋„ CRLF ์ฐจ์ด๋กœ ์ธํ•ด commit์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Œ



  • Editor
git config --global core.editor <editor>

- ์˜ˆ์ œ (Editor)




  • ์ „์ฒด ์„ค์ • ํ™•์ธ
git config --list

- ์˜ˆ์ œ (์ „์ฒด ์„ค์ • ํ™•์ธ) ``` git config --list ```


  • ํ•ญ๋ชฉ๋ณ„ ์„ค์ • ํ™•์ธ
git config <key>

- ์˜ˆ์ œ (Editor)




Git ๊ธฐ๋ณธ ์šฉ์–ด

  • Repository :
    ์†Œ์Šค์ฝ”๋“œ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ Branch๊ฐ€ ๋ชจ์—ฌ์žˆ๋Š” ๋””์Šคํฌ์ƒ์˜ ๋ฌผ๋ฆฌ์  ๊ณต๊ฐ„
    Local Repository์™€ Remote Repository๋กœ ๊ตฌ๋ถ„

  • Checkout :
    ํŠน์ • ์‹œ์ ์ด๋‚˜ Branch์˜ ์†Œ์Šค์ฝ”๋“œ๋กœ ์ด๋™ํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธ
    Checkout ๋Œ€์ƒ - Branch, Commit, Tag
    Checkout์„ ํ†ตํ•ด ๊ณผ๊ฑฐ ์—ฌ๋Ÿฌ ์‹œ์ ์˜ ์ฝ”๋“œ๋กœ ์ด๋™์ด ๊ฐ€๋Šฅ

  • Stage :
    ์ž‘์—…ํ•  ๋‚ด์šฉ์ด ์˜ฌ๋ผ๊ฐ€๋Š” ์ž„์‹œ์ €์žฅ์˜์—ญ
    ์ด ์˜์—ญ์„ ์ด์šฉํ•˜์—ฌ ์ž‘์—…ํ•œ ๋‚ด์šฉ ์ค‘ commit์— ๋ฐ˜์˜ํ•  ํŒŒ์ผ๋งŒ ์„ ๋ณ„ํ•˜์—ฌ commit์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Œ

  • Commit :
    ์ž‘์—…ํ•  ๋‚ด์šฉ์„ Local Repository์— ์ €์žฅํ•˜๋Š” ๊ณผ์ •
    ๊ฐ๊ฐ์˜ commit์€ ์˜๋ฏธ์žˆ๋Š” ๋ณ€๊ฒฝ๋‹จ์œ„์ด๊ณ , ๋ณ€๊ฒฝ์— ๋Œ€ํ•œ ์„ค๋ช…์„ commit log๋กœ ๋‚จ๊น€
    ๊ถŒ์žฅ - commit์„ ์•„๋ผ์ง€ ๋งˆ์„ธ์š”
    ์ฐธ๊ณ  - commit๋‹จ์œ„๋‚˜ commit log format์„ ์ •ํ•ด๋†“์€ ํšŒ์‚ฌ๋‚˜ ํŒ€๋„ ์žˆ์Œ(๋นŒ๋“œ ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ)

  • Tag :
    ์ž„์˜์˜ commit ์œ„์น˜์— ์‰ฝ๊ฒŒ ์ฐพ์•„๊ฐˆ ์ˆ˜ ์žˆ๋„๋ก ๋ถ™์—ฌ๋†“์€ ์ด์ •ํ‘œ
    Tag๊ฐ€ ๋ถ™์€ commit์€ commit id(version) ๋Œ€์‹  tag name์œผ๋กœ ์‰ฝ๊ฒŒ checkout ๊ฐ€๋Šฅ

  • Push :
    Local Repository์˜ ๋‚ด์šฉ ์ค‘, Remote Repository์— ๋ฐ˜์˜๋˜์ง€ ์•Š์€ commit์„ Remote Repository๋กœ ๋ณด๋‚ด๋Š” ๊ณผ์ •
    ๊ถŒ์žฅ - Pushํ•˜๋Š” ์ˆœ๊ฐ„ ๋‹ค๋ฅธ ๊ฐœ๋ฐœ์ž๋“ค๋„ ์˜ํ–ฅ์„ ๋ฐ›์Œ. ๊ฒ€์ฆ๋˜์ง€ ์•Š์€ ์ฝ”๋“œ๋Š” Pushํ•˜์ง€ ์•Š๋„๋ก ํ•จ

  • Pull :
    Remote Repository์— ์žˆ๋Š” ๋‚ด์šฉ ์ค‘, Local Repository์— ๋ฐ˜์˜๋˜์ง€ ์•Š์€ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์™€์„œ Local Repository์— ์ €์žฅํ•˜๋Š” ๊ณผ์ •
    ๋‹ค๋ฅธ ํŒ€์›์ด ๋ณ€๊ฒฝํ•˜๊ณ  Pushํ•œ ๋‚ด์šฉ์„ Local Repository์— ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Œ
    ์ฐธ๊ณ  - Push๊ณผ์ •์—์„œ Conflict(์ถฉ๋Œ)์ด ์ผ์–ด๋‚˜์„œ Push๊ฐ€ ๊ฑฐ์ ˆ๋œ ๊ฒฝ์šฐ, Pull์„ ํ†ตํ•ด Remote Repository์˜ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ Local Repository์— ๋ฐ˜์˜ํ•˜์—ฌ Conflict๋ฅผ ํ•ด๊ฒฐํ•œ ๋’ค ๋‹ค์‹œ Push๋ฅผ ์‹œ๋„ํ•ด์•ผ ํ•จ

  • Branch :
    ํŠน์ • ์‹œ์ (commit ๋‹จ์œ„)์—์„œ ๋ถ„๊ธฐํ•˜์—ฌ ์ƒˆ๋กœ์šด commit์„ ์ƒ‡์„ ์ˆ˜ ์žˆ๋Š” ๊ฐ€์ง€๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ
    ๊ฐœ๋ฐœ์˜ ์ฃผ์ถ•์ด ๋˜๋Š” branch๋ฅผ master branch (ํ˜น์€ main branch)๋ผ๊ณ  ํ•จ
    ๋ชจ๋“  branch๋Š” ์ตœ์ข…์ ์œผ๋กœ ๋‹ค์‹œ master branch์— merge(๋ณ‘ํ•ฉ)๋˜๋Š” ํ˜•์‹์œผ๋กœ ์ง„ํ–‰ ๋จ

  • Merge :
    Branch์˜ ๋ฐ˜๋Œ€๊ฐœ๋…์œผ๋กœ ํ•˜๋‚˜์˜ Branch๋ฅผ ๋‹ค๋ฅธ Branch์™€ ํ•ฉ์น˜๋Š” ๊ณผ์ •
    Merge๋˜๋Š” ๋‘ Branch๋Š” ์ฃผ์ข…๊ด€๊ณ„๊ฐ€ ์„ฑ๋ฆฝ. ์˜ˆ - dev branch๋ฅผ main branch์— merge
    Merge๋˜๋Š” ๊ณผ์ •์—์„œ Conflict(์ถฉ๋Œ)์ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ Diff๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ Conflict๋ฅผ ํ•ด๊ฒฐํ•œ ๋’ค Merge๋ฅผ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Œ




Local Repository ๊ตฌ์„ฑ

  • Local Repository๋Š” Git์ด ๊ด€๋ฆฌํ•˜๋Š” 3๊ฐ€์ง€ ๋‹จ๊ณ„๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Œ
    - Working Directory(์ž‘์—…๊ณต๊ฐ„) : ์‹ค์ œ ์†Œ์Šค ํŒŒ์ผ, ์ƒ์„ฑํ•œ ํŒŒ์ผ๋“ค์ด ์กด์žฌ
    - Index(Stage) : Staging area(์ค€๋น„์˜์—ญ)์˜ ์—ญํ• , git addํ•œ ํŒŒ์ผ๋“ค์ด ์กด์žฌ
    - HEAD : ์ตœ์ข… ํ™•์ •๋ณธ, git commitํ•œ ํŒŒ์ผ๋“ค์ด ์กด์žฌ



Local Repository ์ƒ์„ฑ

  • Workspace ์ƒ์„ฑ
mkdir git_ws
  • ์‹ค์Šต




  • Working Directory ์ƒ์„ฑ : Workspace๋กœ ์ด๋™ํ•œ ๋’ค Working Directory ์ƒ์„ฑ
cd git_ws
mkdir test_project

  • ์‹ค์Šต
cd Documents
mkdir git_ws
cd git_ws 
mkdir test_project
cd test_project




  • Git init : ํด๋”์—์„œ Git์„ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ•ด๋‹น ํด๋”๋ฅผ Git์ด ๊ด€๋ฆฌํ•˜๊ธฐ ์‹œ์ž‘
git init

  • Git init ์‹ค์Šต : ์ƒ์„ฑํ•œ ํด๋”๋กœ ์ด๋™ํ•˜์—ฌ Git init ์„ ์‹คํ–‰ํ•˜๋ฉด Repository ๊ฐ€ ์ƒ์„ฑ๋จ
git init




  • .git ํ™•์ธ : .git ํด๋”๊ฐ€ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธ โ†’ .git์œผ๋กœ ์ด๋™ํ•ด์„œ ํŒŒ์ผ์„ ์‚ดํŽด๋ณด๋ฉด Git ๊ด€๋ จ ํŒŒ์ผ๋“ค์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธ
  • ls -all : ์ˆจ๊ฒจ์ง„ ํŒŒ์ผ๋“ค๋„ ํ™•์ธ ๊ฐ€๋Šฅ

  • ์‹ค์Šต
ls -all




  • ํŒŒ์ผ ์ƒ์„ฑ : Working Directory์— ํŒŒ์ผ์„ ์ƒ์„ฑ
  • touch ๋ช…๋ น์–ด : ๋นˆ ํŒŒ์ผ์„ ์ƒ์„ฑ
touch test.txt
ls

  • ์‹ค์Šต
touch test.txt
ls




  • Git Status : Git์— ์กด์žฌํ•˜๋Š” ํŒŒ์ผ ํ™•์ธ
git status

  • ์‹ค์Šต
git status




  • Git Add : Working Directory์—์„œ ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ์„ Index(stage)์— ์ถ”๊ฐ€
git add <filename>

  • Git Add ์‹ค์Šต
git add test.txt




  • Git Commit : Index (stage)์— ์ถ”๊ฐ€๋œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ HEAD์— ๋ฐ˜์˜(ํ™•์ •)
git commit -m "commit์— ๋Œ€ํ•œ ์„ค๋ช…" <filename>

  • Git Commit ์‹ค์Šต
 git commit -m 'first commit' test.txt




Remote Repository ์ƒ์„ฑ

  • Github์œผ๋กœ ์ด๋™
  • Create respository ๋ฒ„ํŠผ ํด๋ฆญ
  • ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ ์„ค์ •ํ•œ ๋’ค ๋นˆ ํ”„๋กœ์ ํŠธ ์ƒํƒœ๋กœ > Create repository ํด๋ฆญ
  • Remote Repository ์ƒ์„ฑ ํ™•์ธ
  • Github Token ์ƒ์„ฑ : ์–ผ๋งˆ์ „๋ถ€ํ„ฐ ๋ณด์•ˆ์ƒ์˜ ์ด์œ ๋กœ Remote Repository ์ ‘์† ์‹œ ๋น„๋ฐ€๋ฒˆํ˜ธ ๋Œ€์‹  Token ์„ ์‚ฌ์šฉ
  • ์‚ฌ์šฉ์ž ๋ฉ”๋‰ด์—์„œ Settings ์„ ํƒ
  • Developer settings ์„ ํƒ
  • Token ์ด๋ฆ„ ์ž…๋ ฅ + No expiration ์„ ์„ ํƒ + repo ์„ ํƒ > Generate token ๋ฒ„ํŠผ ์„ ํƒ
  • Token ์ƒ์„ฑ ์™„๋ฃŒ - ์ดํ›„์—๋Š” Token ๊ฐ’์ด ๋ณด์ด์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ฐ˜๋“œ์‹œ ์ž˜ ๋ณต์‚ฌํ•ด์•ผ ํ•จ



Remote Repository ๋“ฑ๋ก

  • Local Repository ์— ์—ฐ๋™ํ•  Remote Repository ๋ฅผ ๋“ฑ๋ก (Token ์‚ฌ์šฉ)
  • Remote Repository ์ฃผ์†Œ ํ™•์ธ : ์™ผ์ชฝ ์ƒ๋‹จ ๊ณ ์–‘์ด๋ฅผ ๋ˆŒ๋Ÿฌ์„œ GitHub Home ์œผ๋กœ ์ด๋™ > ์ƒ์„ฑํ•ด๋‘” Remote Repository ์„ ํƒ
  • Remote Repository ๋“ฑ๋ก : HTTPS ์„ ํƒ ํ™•์ธ > ์ฃผ์†Œ ๋ณต์‚ฌ
  • Local Repository ์— Remote Repository ๋“ฑ๋ก : Remote Repository ๋“ฑ๋ก
git remote add origin https://github.com/<repository>.git

  • Remote Repository ๋“ฑ๋ก with Username and Token
git remote add origin http://<username>:<token>@github.com/<repository>.git

  • Remote Repository ๋“ฑ๋ก ์‹ค์Šต
git remote add origin https://zoe-0314:<token>@github.com/zoe-0314/test_project.git

  • Remote Repository ์ •๋ณด ํ™•์ธ
git remote -v

  • Remote Repository ์ •๋ณด ํ™•์ธ ์‹ค์Šต
git remote -v




Remote Repository์— ๋ณ€๊ฒฝ๋‚ด์šฉ Pushํ•˜๊ธฐ

  • Local Repository (HEAD)์— ๋ฐ˜์˜๋œ ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ Remote Repository์—๋„ ๋ฐ˜์˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Git Push๋ฅผ ์‚ฌ์šฉ

  • Git Push

git push origin <branchname>

  • Git Push ์‹ค์Šต
git push origin master

  • Remote Repository ํ™•์ธ : Remote Repository ํŽ˜์ด์ง€์—์„œ ์ƒˆ๋กœ๊ณ ์นจ ํ•˜๋ฉด Push ๋œ ํŒŒ์ผ์ด ๋ณด์ž„




Remote Repository์— Pullํ•˜๊ธฐ

  • Remote Repository์˜ ๋‚ด์šฉ์— ๋งž์ถฐ Local Repository๋ฅผ ๊ฐฑ์‹ ํ•˜๋ ค๋ฉด Git Pull ์‚ฌ์šฉ

  • ReadMe ํŒŒ์ผ ์ƒ์„ฑ : Add a README ๋ฒ„ํŠผ ํด๋ฆญ

  • ๋‚ด์šฉ ํ™•์ธ (๋ชจ๋‘ Default ์„ค์ •์œผ๋กœ)

  • ํ•˜๋‹จ์˜ Commit new file ๋ฒ„ํŠผ ์„ ํƒ

  • README ํŒŒ์ผ ์ƒ์„ฑ ํ™•์ธ



  • Git Pull
git pull origin <branchname>

  • Git Pull ์‹ค์Šต : ReadMe ํŒŒ์ผ์„ Local Repository ๋กœ Pull
git pull origin master

1. Local Repository ์ƒ์„ฑํ•˜๊ธฐ

  • ์œ„์น˜ : git_ws ํด๋” ํ•˜์œ„
  • ์ด๋ฆ„ : exam_project
 mkdir exam_project
git init

2. ํŒŒ์ผ ์ƒ์„ฑ ํ›„ Git ์œผ๋กœ ๊ด€๋ฆฌ ์‹œ์ž‘ํ•˜๊ธฐ

  • ํŒŒ์ผ : exam.txt
  • Index ์ถ”๊ฐ€
  • HEAD ๋“ฑ๋ก
touch exam.txt
git add exam.txt
git status
git commit -m 'first commit' exam.txt
git status

3. Remote Repository ์ƒ์„ฑ ํ•˜๊ธฐ

  • ์ด๋ฆ„ : exam_project
  • ๋นˆ ํ”„๋กœ์ ํŠธ

4. Remote Repository ๋“ฑ๋ก ํ•˜๊ธฐ

  • exam_project ์˜ Local Repository ์— ์•ž์„œ ์ƒ์„ฑํ•œ remote repository ๋“ฑ๋ก ํ›„ ํ™•์ธ
  • token ์€ ์•ž์„œ ์ˆ˜์—…์—์„œ ์ƒ์„ฑํ•œ token ๊ณ„์† ์‚ฌ์šฉ
 git remote add orign https://zoe-0314:<token>@github.com/zoe-0314/exam_project.git
git remote -v

5. Local Repository ๋ณ€๊ฒฝ๋‚ด์šฉ์„ Remote Repository ์— ๋ฐ˜์˜ํ•˜๊ธฐ

  • commit ํ•ญ๋ชฉ์„ Remote Repository ์— ๋ฐ˜์˜
  • Remote Repository ์—์„œ exam.txt ํ™•์ธ
git push orign master
git status

6. Remote Repository ๋ณ€๊ฒฝ ๋‚ด์šฉ์„ Local Repository ์— ๋ฐ˜์˜ํ•˜๊ธฐ

  • exam.txt ํŒŒ์ผ ์ˆ˜์ • : This is git exam
  • ์ฐธ๊ณ  > ํŒŒ์ผ ์ˆ˜์ •ํ•˜๋Š” ๋ฒ• (ํŒŒ์ผ ๋ชฉ๋ก์—์„œ ํŒŒ์ผ ํด๋ฆญ โ†’ ํŒŒ์ผ ์ˆ˜์ • ๋ฒ„ํŠผ ํด๋ฆญ โ†’ ํŒŒ์ผ ๋‚ด์šฉ ์ˆ˜์ • (์ž…๋ ฅ) โ†’ ํ•˜๋‹จ์˜ Commit ๋ฒ„ํŠผ ํด๋ฆญ โ†’ ์ˆ˜์ • ํ™•์ธ โ†’ Local Repository ์— ๋ฐ˜์˜ ํ›„ ๋‚ด์šฉ ํ™•์ธ)
  • cat : ํŒŒ์ผ ๋‚ด์šฉ ํ™•์ธ
git pull orign master
ls
cat exam.txt 

7. Commit ๋งŒ๋“ค๊ณ  ๊ฐ๊ฐ์„ Local ๊ณผ Remote ์— ๋ฐ˜์˜ํ•˜๊ธฐ

  • Commit 1 : Local Repository ์—์„œ exam2.txt ์ƒ์„ฑ ํ›„ Remote Repository ์— ๋ฐ˜์˜, ํ™•์ธ
touch exam2.txt
git status
git add exam2.txt
git commit -m 'exam2.txt' exam2.txt
git push orign master
  • Commit 2 : Remote Repository ์—์„œ exam2.txt ์ˆ˜์ • ํ›„ Local Repository ์— ๋ฐ˜์˜, ํ™•์ธ - This is git exam2.
git pull orign master
cat exam2.txt
  • Commit 3 : Local Repository ์—์„œ exam3.txt ์ƒ์„ฑ ํ›„ Remote Repository ์— ๋ฐ˜์˜, ํ™•์ธ - This is git exam3.
 touch exam3.txt

exam3.txt ํŒŒ์ผ์— ๊ธ€ ์ž…๋ ฅํ•˜๊ธฐ(๊ธ€ ์ž…๋ ฅํ•˜๊ณ  ctrl + d๋กœ ์ €์žฅํ•˜๋ฉด ๋‚˜์™€์ง)

cat > exam3.txt
cat exam3.txt
git add exam3.txt
git status
git commit -m 'commit 3' exam3.txt
git status
git push orign master
  • Commit 4 : Remote Repository ์—์„œ exam3.txt ์ˆ˜์ • ํ›„ Local Repository ์— ๋ฐ˜์˜, ํ™•์ธ - This is commit exam.
 git pull orign master
cat exam3.txt




Remote Repository ์ƒ์„ฑ

  • Git Home ์—์„œ Repositoreis 'New' ๋ฒ„ํŠผ ์„ ํƒ

  • HelloGit ์ƒ์„ฑ : README File & .gitignore (python) ์„ ํƒ > Create repository

  • HelloGit ์ƒ์„ฑ ํ™•์ธ

  • README FILE : ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ ์„ค๋ช…, ์‚ฌ์šฉ๋ฐฉ๋ฒ•, ๋ผ์ด์„ผ์Šค, ์„ค์น˜๋ฐฉ๋ฒ• ๋“ฑ์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ๊ธฐ์ˆ ํ•˜๋Š” ํŒŒ์ผ, ๋‚˜, ์ง์žฅ๋™๋ฃŒ, ํ”„๋กœ๊ทธ๋žจ ์‚ฌ์šฉ์ž๋ฅผ ์œ„ํ•ด ์กด์žฌ

  • gitignore : Git ๋ฒ„์ „ ๊ด€๋ฆฌ์—์„œ ์ œ์™ธํ•  ํŒŒ์ผ๋ชฉ๋ก์„ ์ง€์ •ํ•˜๋Š” ํŒŒ์ผ, ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜์ง€ ์•Š๋Š” ํŒŒ์ผ๋“ค์„ ์ž๋™์œผ๋กœ commit ๋Œ€์ƒ์—์„œ ์ œ์™ธ์‹œ์ผœ ์คŒ





Default Branch

  • Default Branch : ์ˆ˜์ • ๊ฐ€๋Šฅ
  • Default Branch ์„ค์ • : Remote Repository๋ฅผ ์ƒ์„ฑํ•  ๋•Œ Default Branch ์ด๋ฆ„์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Œ
    - ์‚ฌ์šฉ์ž ๋ฉ”๋‰ด > Settings
    - Repository > Repository default branch



Remote Repository ๋ณต์ œํ•˜๊ธฐ

  • Local Repository ๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ Git Clone ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ Remote Repository ๋ฅผ Local ์— ๋ณต์ œํ•  ์ˆ˜ ์žˆ์Œ

  • Git Clone :
    ์•ž์„œ ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ 

  • Git Init ์œผ๋กœ ํ•ด๋‹น ํด๋”๋ฅผ ์ดˆ๊ธฐํ™” ํ•˜๊ณ 
  • Remote Repository ๋ฅผ ๋“ฑ๋กํ•˜๊ณ 
  • Remote Repository ์˜ ๋‚ด์šฉ์„ Pull ํ•˜๋Š” ๋ชจ๋“  ๊ณผ์ •์„ Git Clone ์œผ๋กœ ํ• ์ˆ˜ ์žˆ์Œ
git clone https://github.com/<repositoroy>.git

  • Git clone with username and token
git clone https://<username>:<token>@github.com/<repository>.git

  • Git Clone ์‹ค์Šต :

Remote Repository ์ฃผ์†Œ ๋ณต์‚ฌ
Workspace ๋กœ ์ด๋™ํ•˜์—ฌ Clone

git clone https://zoe-0314:<token>@github.com/zoe-0314/HelloGit.git

Local Repository ์ƒ์„ฑ ํ™•์ธ

ls
cd HelloGit
cat README.md
ls -all




Branch

  • Branch ์กฐํšŒ(Local Branch)
git branch

  • Branch ์กฐํšŒ (Local Branch) ์‹ค์Šต
git branch




  • Branch ์กฐํšŒ(Remote Branch)
git branch -r

  • Branch ์กฐํšŒ (Remote Branch) ์‹ค์Šต
gir branch -r




  • Branch ์กฐํšŒ (Local + Remote)
git branch -a

  • Branch ์กฐํšŒ (Local + Remote) ์‹ค์Šต
git branch -a




  • Branch ์ƒ์„ฑ
git branch <branchname>

  • Branch ์ƒ์„ฑ ์‹ค์Šต
git branch branch01




  • Branch ์ด๋™
git checkout <branchname>

  • Branch ์ด๋™ ์‹ค์Šต
git checkout branch01
git branch




  • Branch ์ƒ์„ฑ + ์ด๋™
git checkout -b <branchname>

  • Branch ์ƒ์„ฑ + ์ด๋™ ์‹ค์Šต
git checkout -b branch02
git branch




  • GitHub์—์„œ Branch ํ™•์ธ : Local Repository ์— ์ƒ์„ฑ๋œ Branch ๋Š” Remote Repository (GitHub) ์—์„œ ๋ณด์ด์ง€์•Š์Œ




  • Branch ์ƒ์„ฑ
git push origin <branchname>

  • Branch ์ƒ์„ฑ (Remote Repository) ์‹ค์Šต 1
git push origin branch01
git branch -a
  • Branch ์ƒ์„ฑ (Remote Repository) ์‹ค์Šต 2
git push origin branch02
git branch -a




  • Branch ์‚ญ์ œ (Local Repository)
git branch -d <branchname>

  • Branch ์‚ญ์ œ (Local Repository) ์‹ค์Šต 1 (์‚ญ์ œํ•  branch์— ๋จธ๋ฌผ๋Ÿฌ ์žˆ์œผ๋ฉด ์‚ญ์ œ๊ฐ€ ์•ˆ๋จ)
 git branch -d branch02
 git checkout main
  • Branch ์‚ญ์ œ (Local Repository) ์‹ค์Šต 2
git branch -d branch02
git branch
  • Branch ์‚ญ์ œ (Local Repository) ์‹ค์Šต 3
git branch -d branch01
git branch -a




  • Branch ์‚ญ์ œ (Remote Repository)
git push origin --delete <branchname>

  • Branch ์‚ญ์ œ (Remote Repository) ์‹ค์Šต 1
git push origin --delete branch02
git branch -a
  • Branch ์‚ญ์ œ (Remote Repository) ์‹ค์Šต 2
 git push origin --delete branch01
git branch -a

1. Remote Repository ์ƒ์„ฑํ•˜๊ธฐ

  • ์ด๋ฆ„ : branch_project
  • Option : README.md, .gitignore (Python)

2. Local ์— Clone

  • ์œ„์น˜ : git_ws ํ•˜์œ„
  • ์ƒ์„ฑ ํ™•์ธ
  • cd .. : ์ƒ์œ„ ํด๋” ์ด๋™
cd ..
git clone https://zoe-0314:<token>@github.com/zoe-0314/branch_project.git
ls -all

3. Branch ์ƒ์„ฑ ํ›„ ์ด๋™

  • ์ด๋ฆ„ : branch01, branch02
  • ์ด๋™ : branch01
  • ํ™•์ธ : Local Branch ๋ชฉ๋ก (ํ˜„์žฌ Branch ์œ„์น˜ - branch01)
cd branch_project
 git branch branch01
git checkout -b branch02
git checkout branch01
git branch -a

4. Branch Push

  • Push : branch01, branch02
  • ํ™•์ธ : Remote Branch ๋ชฉ๋ก, GitHub
git push origin branch01
git push origin branch02
git branch -a

5. Local Branch ์‚ญ์ œ

  • Local Branch ์‚ญ์ œ : branch01
  • ํ™•์ธ : Local Branch ๋ชฉ๋ก (์—๋Ÿฌ์ƒํ™ฉ ์ฒ˜๋ฆฌ ํฌํ•จ)
git checkout main
git branch -d branch01
git branch -a

6. ๋‚จ์€ Local Branch ๋ชจ๋‘ ์‚ญ์ œ

  • main branch ์ œ์™ธ
  • ํ™•์ธ : ์ „์ฒด Branch ๋ชฉ๋ก
git branch -d branch02
git branch -a

7. Remote Branch ๋ชจ๋‘ ์‚ญ์ œ

  • main, HEAD ์ œ์™ธ
  • ํ™•์ธ : ์ „์ฒด Branch ๋ชฉ๋ก , GitHub
git push origin --delete branch01
git push origin --delete branch02
git branch -a

์ƒ์†Œํ•˜๋‹ค..์–ด๋ ต..

๐Ÿ’ป ์ถœ์ฒ˜ : ์ œ๋กœ๋ฒ ์ด์Šค ๋ฐ์ดํ„ฐ ์ทจ์—… ์Šค์ฟจ

profile
#๋ฐ์ดํ„ฐ๋ถ„์„ #ํผํฌ๋จผ์Šค๋งˆ์ผ€ํŒ… #๋ฐ์ดํ„ฐ #๋””์ง€ํ„ธ๋งˆ์ผ€ํŒ…

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