Bibi's DevLog ๐Ÿค“๐ŸŽ

[์ง€์˜ฅ์—์„œ ์˜จ Git] 5. ๊นƒํ—ˆ๋ธŒ๋กœ ํ˜‘์—… - ๊ณต๋™ ์ž‘์—…์ž์™€ ์›๊ฒฉ์ €์žฅ์†Œ ๋ฐ ๋ธŒ๋žœ์น˜ ์‚ฌ์šฉ ๋ณธ๋ฌธ

ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Git & GIthub ๊นƒ๊ณผ ๊นƒํ—ˆ๋ธŒ

[์ง€์˜ฅ์—์„œ ์˜จ Git] 5. ๊นƒํ—ˆ๋ธŒ๋กœ ํ˜‘์—… - ๊ณต๋™ ์ž‘์—…์ž์™€ ์›๊ฒฉ์ €์žฅ์†Œ ๋ฐ ๋ธŒ๋žœ์น˜ ์‚ฌ์šฉ

๋น„๋น„ bibi 2021. 2. 10. 01:47

5. ๊นƒํ—ˆ๋ธŒ๋กœ ํ˜‘์—…ํ•˜๊ธฐ

5.1 ์›๊ฒฉ ์ €์žฅ์†Œ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ

ํ•˜๋‚˜์˜ ๊นƒํ—ˆ๋ธŒ ๊ณ„์ •์œผ๋กœ ๋‘˜ ์ด์ƒ์˜ ์ปดํ“จํ„ฐ์—์„œ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๊ณต์œ ํ•ด ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

์›๊ฒฉ ์ €์žฅ์†Œ ๋ณต์ œํ•˜๊ธฐ (clone)

ํด๋ก clone
: ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ์ง€์—ญ ์ €์žฅ์†Œ๋กœ ๋˜‘๊ฐ™์ด ๋ณต์ œํ•˜๋Š” ๊ฒƒ.

  • ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ํด๋ก ํ•˜๋ฉด, ๋ณต์ œ๋œ ์ง€์—ญ ์ €์žฅ์†Œ์™€ ์›๊ฒฉ ์ €์žฅ์†Œ๋Š” ์ž๋™์œผ๋กœ ์—ฐ๊ฒฐ๋œ๋‹ค.

ํด๋ก  ์ ˆ์ฐจ

  1. ๊นƒํ—ˆ๋ธŒ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ Code๋ฅผ ๋ˆ„๋ฅด๊ณ , ์›๊ฒฉ ์ €์žฅ์†Œ์˜HTTPS๋งํฌ๋ฅผ ๋ณต์‚ฌํ•œ๋‹ค.
  2. ํด๋ก ํ•  ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“ค ์œ„์น˜๋กœ ์ด๋™ํ•œ ํ›„ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
    • git clone HTTPS๋งํฌ ๋””๋ ‰ํ† ๋ฆฌ๋ช…
      : HTTPS๋งํฌ์˜ ์›๊ฒฉ์ €์žฅ์†Œ๋ฅผ ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๋กœ ํด๋ก ํ•จ (ํ•ด๋‹น ์ด๋ฆ„์ด ์—†์œผ๋ฉด ์ƒˆ๋กœ ์ƒ์„ฑ)
    • git clone HTTPS๋งํฌ .
      : HTTPS๋งํฌ์˜ ์›๊ฒฉ์ €์žฅ์†Œ๋ฅผ ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์— ํด๋ก ํ•จ

๊ฐœ์ธ ์ปดํ“จํ„ฐ์—์„œ ์ž‘์—… ํ›„, ์›๊ฒฉ ์ €์žฅ์†Œ์— ์˜ฌ๋ฆฌ๊ธฐ

์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ clone์œผ๋กœ ๋ณต์ œํ•œ ๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ์ž‘์—… ํ›„, ์ปค๋ฐ‹-ํ‘ธ์‹œ ํ•œ๋‹ค.

  • git commit -am "์ปค๋ฐ‹๋ฉ”์‹œ์ง€"
  • git push

ํšŒ์‚ฌ ์ปดํ“จํ„ฐ์—์„œ ์ž‘์—… ํ›„, ์›๊ฒฉ ์ €์žฅ์†Œ์— ์˜ฌ๋ฆฌ๊ธฐ

์œ— ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์น˜๋ฉฐ, ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ๋‚ด์šฉ์ด ํšŒ์‚ฌ ์ปดํ“จํ„ฐ์˜ ์ง€์—ญ์ €์žฅ์†Œ ๋‚ด์šฉ๊ณผ ๋‹ฌ๋ผ์กŒ๋‹ค.
๋”ฐ๋ผ์„œ ํšŒ์‚ฌ ์ปดํ“จํ„ฐ์—์„œ ์ž‘์—…ํ•˜๊ธฐ ์ „์— ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹ ๋ณ€๊ฒฝ๋‚ด์—ญ์„ ๊ฐ€์ ธ์™€์•ผ ํ•œ๋‹ค(ํ’€ pull)

  • git pull
    (ํšŒ์‚ฌ ์ปดํ“จํ„ฐ์˜ ์ง€์—ญ ์ €์žฅ์†Œ์—์„œ)

  • ๋‚ด๋ ค๋ฐ›์€ ๋‚ด์—ญ์„ ๊ฐ€์ง€๊ณ  ์ž‘์—… ํ›„,
    git commit -am "์ปค๋ฐ‹๋ฉ”์‹œ์ง€"
    git push

์ดํ›„ ๋‹ค์‹œ ๊ฐœ์ธ ์ปดํ“จํ„ฐ์—์„œ ์ž‘์—…ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ git pull ๋จผ์ € ํ•œ ๋‹ค์Œ ์ž‘์—…ํ•˜๊ณ , ๊ทธ ๋’ค git commit - git push ํ•˜๋ฉด ๋œ๋‹ค.

5.2 ์›๊ฒฉ ๋ธŒ๋žœ์น˜ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ

git pull๋กœ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹์„ ๊ฐ€์ ธ์˜ค๊ธฐ ์ „์—, ์›๊ฒฉ ์ €์žฅ์†Œ์— ์–ด๋–ค ๋ณ€ํ™”๊ฐ€ ์žˆ์—ˆ๋Š”์ง€ ์ •๋ณด๋ฅผ ๋ฏธ๋ฆฌ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์›๊ฒฉ master ๋ธŒ๋žœ์น˜

๋กœ์ปฌ์ €์žฅ์†Œ์˜ master๋ธŒ๋žœ์น˜์ฒ˜๋Ÿผ, ์›๊ฒฉ์ €์žฅ์†Œ๋„ ๋งŒ๋“ค ๋•Œ master๋ธŒ๋žœ์น˜๊ฐ€ ๊ธฐ๋ณธ ์ƒ์„ฑ๋จ.

$ git log
commit 7942f91d298d355e4fe1679553c65603a5765752 (HEAD -> master, origin/master, origin/HEAD)
Author: Haina <bibi6666667@kakao.com>
Date:   Tue Feb 9 22:45:03 2021 +0900

    add c
  • HEAD -> master : ์ด ์ปค๋ฐ‹์ด ์ง€์—ญ ์ €์žฅ์†Œ์˜ ์ตœ์ข… ์ปค๋ฐ‹์ž„์„ ์˜๋ฏธํ•จ.
  • origin/master, origin/HEAD(๋นจ๊ฐ„์ƒ‰) : ์ด ์ปค๋ฐ‹์ด ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ตœ์ข… ์ปค๋ฐ‹์ž„์„ ์˜๋ฏธํ•จ.
rnala@DESKTOP-SL978IQ MINGW64 ~/git_home (master)
$ git log --oneline
cc70393 (HEAD -> master) create f3.txt
7942f91 (origin/master, origin/HEAD) add c
4b0204e Create f2.txt
2c6193f add b
14e8677 add a

rnala@DESKTOP-SL978IQ MINGW64 ~/git_home (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
  • ์œ„์ฒ˜๋Ÿผ (HEAD -> master)์˜ ์œ„์น˜์™€ (origin/master, origin/HEAD)์˜ ์œ„์น˜๊ฐ€ ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒƒ์€ ๋กœ์ปฌ ์ €์žฅ์†Œ ์ƒํƒœ์™€ ์›๊ฒฉ ์ €์žฅ์†Œ ์ƒํƒœ๊ฐ€ ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•จ.
  • git status๋กœ ์ƒํƒœ๋ฅผ ๋ณด๋ฉด,
    Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) ์™€ ๊ฐ™์ด
    ํ˜„์žฌ ๋กœ์ปฌ ์ €์žฅ์†Œ์˜ master ๋ธŒ๋žœ์น˜๊ฐ€ ์›๊ฒฉ ์ €์žฅ์†Œ(origin)์˜ master๋ธŒ๋žœ์น˜๋ณด๋‹ค 1 ์ปค๋ฐ‹ ์•ž์„œ ์žˆ๋‹ค๊ณ  ์•Œ๋ฆผ์ด ๋œธ.
    -> git push๋ฅผ ํ†ตํ•ด ๋กœ์ปฌ ์ €์žฅ์†Œ ์ปค๋ฐ‹์„ ์›๊ฒฉ ์ €์žฅ์†Œ๋กœ ์˜ฌ๋ ค์„œ ๋‘˜์„ ๋งž์ถฐ ์ฃผ์–ด์•ผ ํ•จ.
  • git push์ดํ›„์—๋Š” ๋‹ค์‹œ (HEAD -> master, origin/master, origin/HEAD) ์ƒํƒœ๊ฐ€ ๋จ.

โ— git push์—์„œ, ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜ ๋ฐœ์ƒ์‹œ

$ git push
To https://github.com/bibi6666667/github_test.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/bibi6666667/github_test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
  • ์›์ธ : fetch๋ฅผ ํ•˜์ง€ ์•Š๊ณ  pushํ•œ ๊ฒฝ์šฐ ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜. (๋‹ค์Œ ๋ฌธ๋‹จ์˜ ๋‚ด์šฉ ์ฐธ๊ณ )
  • ํ•ด๊ฒฐ 1 : git push origin +master (๋น„์ถ”์ฒœ - ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ๊ธฐ์กด ๋ฐ์ดํ„ฐ๋Š” ๋ณด์žฅํ•  ์ˆ˜ ์—†์Œ)
  • ํ•ด๊ฒฐ 2 : pull์„ ๋จผ์ € ํ•ด์„œ ์›๊ฒฉ์ €์žฅ์†Œ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์€ ๋’ค ๋‹ค์‹œ push

์›๊ฒฉ ๋ธŒ๋žœ์น˜ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ (fetch)

ํŒจ์น˜ fetch
: ๋ถˆ๋Ÿฌ์˜ค๋‹ค, ๊ฐ€์ ธ์˜ค๋‹ค์˜ ์˜๋ฏธ.

  • git fetch
    : ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋ช…๋ น์–ด.
  • git fetch์™€ git pull์˜ ์ฐจ์ด์ ์€?
    : pull์€ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹์„ ๊ฐ€์ ธ์™€ ๋ฌด์กฐ๊ฑด ๋กœ์ปฌ์ €์žฅ์†Œ์— ํ•ฉ์นœ๋‹ค
    fetch๋Š” ์›๊ฒฉ ๋ธŒ๋žœ์น˜์— ์ผ์–ด๋‚œ ์ •๋ณด๋งŒ ๊ฐ€์ ธ์˜จ๋‹ค.
  • ์šฉ๋„
    : ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ˆ˜์ • ๋‚ด์—ญ์„ ํ™•์ธํ•œ ๋‹ค์Œ์— ์ง€์—ญ ์ €์žฅ์†Œ์™€ ํ•ฉ์น˜๊ณ  ์‹ถ์„ ๋•Œ,
    fetch๋กœ ์ปค๋ฐ‹์„ ๊ฐ€์ ธ์™€ ํ™•์ธํ•œ ๋’ค ๊ดœ์ฐฎ์œผ๋ฉด pull๋กœ ํ•ฉ์น˜๋ฉด ๋œ๋‹ค.
rnala@DESKTOP-SL978IQ MINGW64 ~/git_office (master)
$ git fetch
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), 587 bytes | 45.00 KiB/s, done.
From https://github.com/bibi6666667/github_test
   5b12a9f..ef8e7de  master     -> origin/master

rnala@DESKTOP-SL978IQ MINGW64 ~/git_office (master)
$ git status
On branch master
Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean

rnala@DESKTOP-SL978IQ MINGW64 ~/git_office (master)
$ git log --oneline
5b12a9f (HEAD -> master) add d
7942f91 add c
4b0204e Create f2.txt
2c6193f add b
14e8677 add a
  • git fetch๋ฅผ ํ•˜๋ฉด..
    • git status์—๋Š”
      Your branch is behind 'origin/master' by 2 commits, and can be fast-forwarded. (use "git pull" to update your local branch) ๋ผ๋Š” ์•ˆ๋‚ด๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค.
      โ†’ ๋‚ด ๋ธŒ๋žœ์น˜(๋กœ์ปฌ ์ €์žฅ์†Œ)๊ฐ€ origin/master(์›๊ฒฉ์ €์žฅ์†Œ)๋ณด๋‹ค 2์ปค๋ฐ‹ ๋’ค์ฒ˜์ ธ ์žˆ๊ณ , fast-forward๊ฐ€๋Šฅํ•˜๋‹ค. git pull์„ ํ†ตํ•ด ์ง€์—ญ ์ €์žฅ์†Œ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋ผ.
    • git log์— (HEAD -> master)๋งŒ ๋ณด์ด๊ณ , origin/master๋Š” ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค.
      ์™œ? ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ตœ์‹  ์ปค๋ฐ‹์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๊ธด ํ–ˆ์ง€๋งŒ, ์•„์ง ์ง€์—ญ ์ €์žฅ์†Œ์— ํ•ฉ์น˜์ง€ ์•Š์€ ์ƒํƒœ์ด๊ธฐ ๋•Œ๋ฌธ.
    • ์ฆ‰ fetch๋กœ ๊ฐ€์ ธ์˜จ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ตœ์‹  ์ •๋ณด๋Š”,
      origin/master๋ธŒ๋žœ์น˜๊ฐ€ ์•„๋‹Œ FETCH_HEAD๋ผ๋Š” ๋ธŒ๋žœ์น˜๋กœ ๊ฐ€์ ธ์˜จ๋‹ค.
  • git fetch๋กœ ๊ฐ€์ ธ์˜จ ์›๊ฒฉ ๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์„ ๋ณด๋ ค๋ฉด..
    • git checkout FETCH_HEAD
      : FETCH_HEAD๋ธŒ๋žœ์น˜๋กœ ์ฒดํฌ์•„์›ƒ.
    • (FETCH_HEAD์—์„œ)git log
      : FECTH_HEAD๋ธŒ๋žœ์น˜์— ์ €์žฅ๋œ ์›๊ฒฉ๋ธŒ๋žœ์น˜์˜ ์ตœ์‹  ์ปค๋ฐ‹์„ ํ™•์ธ ๊ฐ€๋Šฅ.
      (ํ•ด๋‹น ๋ธŒ๋žœ์น˜ ์ตœ์‹  ์ปค๋ฐ‹์—origin/master, origin/HEAD๊ฐ€ ํ‘œ์‹œ๋˜์–ด ์žˆ๋‹ค)
    • git diff HEAD ofigin/master
      : ์ง€์—ญ ์ €์žฅ์†Œ์˜ ์ตœ์‹  ์ปค๋ฐ‹๊ณผ fetchํ•œ ์ปค๋ฐ‹์˜ ์ฐจ์ด๋ฅผ ๋น„๊ตํ•จ
  • ํŒจ์น˜๋กœ ๊ฐ€์ ธ์˜จ ๋‚ด์šฉ์„ ํ˜„์žฌ ๋ธŒ๋žœ์น˜์— ํ•ฉ์น˜๋ ค๋ฉด..
    • git pull ๋กœ ์›๊ฒฉ ์ €์žฅ์†Œ ์†Œ์Šค ๋‚ด๋ ค๋ฐ›๊ธฐ
    • git merge FETCH_HEAD๋กœ FETCH_HEAD๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹ ๋ณ‘ํ•ฉํ•˜๊ธฐ (์ถ”์ฒœ)
      (git merge origin/master : ์›๊ฒฉmaster๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹์„ ๋ณ‘ํ•ฉํ•˜๋„๋ก ์ง€์ •)
      (git merge origin/๋ธŒ๋žœ์น˜๋ช… : ์›๊ฒฉ ํ•ด๋‹น ๋ธŒ๋žœ์น˜์˜ ์ปค๋ฐ‹์„ ๋ณ‘ํ•ฉํ•˜๋„๋ก ์ง€์ •)

โœ” ์ƒ๊ฐํ•ด๋ณด๋ฉด, ๊ฒฐ๊ตญ git pull ๋ช…๋ น์€..

: git fetch์™€ git merge FETCH_HEAD ๋ฅผ ํ•ฉ์นœ ๊ฒƒ๊ณผ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ๋ช…๋ น์–ด์ด๋‹ค.

5.3 ๊นƒํ—ˆ๋ธŒ ํ˜‘์—…์˜ ๊ธฐ๋ณธ ์ ˆ์ฐจ

๊นƒํ—ˆ๋ธŒ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ์‚ฌ์šฉํ•ด ํ˜‘์—…ํ•  ๋•Œ, ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ์ ˆ์ฐจ์™€ ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณธ๋‹ค.

๊ณต๋™ ์ž‘์—…์ž Collaborators ์ถ”๊ฐ€

๊นƒํ—™ public repository๋Š” ์ฃผ์†Œ๋งŒ ์•Œ๋ฉด ๋ˆ„๊ตฌ๋“  ์†Œ์Šค๋ฅผ ๋ณด๊ณ , ๋‹ค์šด๋กœ๋“œ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

ํ•˜์ง€๋งŒ ๋ˆ„๊ตฌ๋‚˜ ์ €์žฅ์†Œ์— ์ปค๋ฐ‹์„ ํ‘ธ์‹œํ•  ์ˆ˜๋Š” ์—†๋‹ค. (์†Œ์Šค๊ฐ€ ๋ฌด๋ถ„๋ณ„ํ•˜๊ฒŒ ์ˆ˜์ •๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ)

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๊ณต๊ฐœ/๋น„๊ณต๊ฐœ ์ €์žฅ์†Œ์—์„œ ํ˜‘์—…ํ•˜๋ ค๋ฉด, ์Šน์ธ๋œ ๊ณต๋™ ์ž‘์—…์ž(Collaborators)์—๊ฒŒ๋งŒ ์ปค๋ฐ‹์„ ์˜ฌ๋ฆด ๊ถŒํ•œ์„ ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

  1. ํŒ€์› ์ค‘ ํ•œ ๋ช…์ด ๊นƒํ—™ ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ ๋‹ค.
  2. ๋‚˜๋จธ์ง€ ํŒ€์›๋“ค์„ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ๊ณต๋™ ์ž‘์—…์ž๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค.
    • Settings - Manage access - Invite a collaborator
    • ์ดˆ๋Œ€ํ•  ํŒ€์›์˜ ๊นƒํ—™ ์•„์ด๋””/๋ฉ”์ผ์ฃผ์†Œ ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์ดˆ๋Œ€๋ฅผ ๋ณด๋‚ธ๋‹ค.
    • ์ดˆ๋Œ€๋ฅผ ๋ฐ›์€ ํŒ€์›์ด Accept Invitation์„ ๋ˆ„๋ฅด๋ฉด ์ถ”๊ฐ€๊ฐ€ ์™„๋ฃŒ๋œ๋‹ค.

์ž‘์—… ํ™˜๊ฒฝ ๊ตฌ์„ฑ

๊ณต๋™ ์ž‘์—…์ž๋“ค์€ ์„œ๋กœ ๋‹ค๋ฅธ ์ปดํ“จํ„ฐ๋“ค์—์„œ ํ•˜๋‚˜์˜ ๊นƒํ—ˆ๋ธŒ์— ์ ‘์†ํ•ด, ๋ฒˆ๊ฐˆ์•„ ์ปค๋ฐ‹์„ ์˜ฌ๋ฆฌ๊ณ  ๋‚ด๋ ค๋ฐ›์œผ๋ฉด์„œ ์ž‘์—…ํ•ด์•ผ ํ•œ๋‹ค.

  1. ๊ฐ ์ž‘์—…์ž์˜ ์ปดํ“จํ„ฐ์— ๋กœ์ปฌ ์ €์žฅ์†Œ๋ฅผ ๋งŒ๋“ค๊ณ , ๊ณต๋™ ์ž‘์—…์—์„œ ์‚ฌ์šฉํ•  ์ด๋ฆ„ ๋ฐ ์ด๋ฉ”์ผ์ฃผ์†Œ๋ฅผ ์ง€์ •ํ•œ๋‹ค.
    • git init ๋กœ์ปฌ์ €์žฅ์†Œ์ด๋ฆ„
    • cd ๋กœ์ปฌ์ €์žฅ์†Œ์ด๋ฆ„
    • git config user.name "์‚ฌ์šฉ์ž์ด๋ฆ„"
    • git config user.email ๋ฉ”์ผ ์ฃผ์†Œ

์›๊ฒฉ ์ €์žฅ์†Œ์— ์ฒซ ์ปค๋ฐ‹ ํ‘ธ์‹œ

  1. ์ฒซ ๋ฌธ์„œ๋ฅผ ์ž‘์—…ํ•˜๊ณ , ์Šคํ…Œ์ด์ง• ๋ฐ ์ปค๋ฐ‹ํ•œ๋‹ค
    • vim ์ฒซ๋ฌธ์„œ.txt
    • git add ์ฒซ๋ฌธ์„œ.txt
    • git commit -m "์ฒซ ์ปค๋ฐ‹"
  2. ์ง€์—ญ ์ €์žฅ์†Œ์˜ ์ปค๋ฐ‹์„ ์›๊ฒฉ ์ €์žฅ์†Œ์— ํ‘ธ์‹œํ•œ๋‹ค
    • git remote add origin ์›๊ฒฉ์ €์žฅ์†ŒHTTPS์ฃผ์†Œ
      : ์›๊ฒฉ์ €์žฅ์†Œ ์ฃผ์†Œ๋ฅผ ์ง€์—ญ์ €์žฅ์†Œ์˜ origin์œผ๋กœ ์ง€์ •ํ•จ
    • git push -u origin master
      : origin์˜ master๋ธŒ๋žœ์น˜์— ์ปค๋ฐ‹์„ ํ‘ธ์‹œํ•จ
      (-u : ๋‹ค์Œ๋ถ€ํ„ฐ๋Š” git push๋งŒ์œผ๋กœ ์ปค๋ฐ‹์„ ํ‘ธ์‹œํ•  ์ˆ˜ ์žˆ๋Š” ์˜ต์…˜)

๊ณต๋™ ์ž‘์—…์ž ์ปดํ“จํ„ฐ์— ์›๊ฒฉ ์ €์žฅ์†Œ ๋ณต์ œ

  1. ๊ณต๋™ ์ž‘์—…์ž๋“ค์€ ๊ฐ์ž ์ž์‹ ์˜ ์ž‘์—…์„ ์ง„ํ–‰ํ•˜๊ธฐ ์ „์—, ๋กœ์ปฌ ์ €์žฅ์†Œ์— ์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ ๋ณต์ œํ•œ๋‹ค
    • git clone ์›๊ฒฉ์ €์žฅ์†Œ์ฃผ์†Œ

์ฒซ ๋ฒˆ์งธ ์ปค๋ฐ‹์ด ์•„๋‹ˆ๋ผ๋ฉด ํ’€ ๋จผ์ €

๊นƒํ—ˆ๋ธŒ ํ˜‘์—…์€ ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ๋ฌธ์„œ๋ฅผ ์ˆ˜์ •ํ•˜๊ณ  ํ‘ธ์‹œํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์ž‘์—… ์ „์— ๋ฐ˜๋“œ์‹œ ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ตœ์‹  ์ปค๋ฐ‹์„ ํ’€ํ•œ ๋‹ค์Œ ๋‚˜์˜ ์ปค๋ฐ‹์„ ํ‘ธ์‹œํ•ด์•ผ ํ•œ๋‹ค.

์›๊ฒฉ ์ €์žฅ์†Œ๋ฅผ cloneํ•œ ๋’ค์—๋„ ์›๊ฒฉ ์ €์žฅ์†Œ์— ์ƒˆ ์ปค๋ฐ‹์ด ์˜ฌ๋ผ์˜ฌ ์ˆ˜ ์žˆ๊ธฐ ๋–„๋ฌธ์ด๋‹ค.

๊ฐ ์ž‘์—…์ž๋“ค์€ ํ’€ pull - ์ปค๋ฐ‹ commit - ํ‘ธ์‹œ push ์ˆœ์„œ๋Œ€๋กœ ์ž‘์—…ํ•ด์•ผ ํ•œ๋‹ค.

  1. ๊ณต๋™ ์ž‘์—…์ž๋“ค์€ ์ž‘์—… ์‹œ์ž‘ ์ „์— ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ํ’€pull์„ ์ง„ํ–‰ํ•œ๋‹ค

    • git pull

    • โ—pull์„ ๋จผ์ € ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ  ํ˜ผ์ž ์ž‘์—…ํ•œ ๋’ค add-commit-pushํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ! [rejected] ...

      $ git push To https://github.com/bibi6666667/github_test.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/bibi6666667/github_test.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

      ๋ฐœ์ƒ ์ด์œ  : ์›๊ฒฉ์ €์žฅ์†Œ์˜ ์ตœ์‹  ์ปค๋ฐ‹ ์ •๋ณด๊ฐ€ ํŒ€์›์˜ ๋กœ์ปฌ ์ €์žฅ์†Œ์— ์ €์žฅ๋˜์–ด ์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ.
      ํ•ด๊ฒฐ : ์ปค๋ฐ‹์„ ํ‘ธ์‹œํ•˜๊ธฐ ์ „์—, git pull๋กœ ์›๊ฒฉ์ €์žฅ์†Œ์˜ ์ตœ์‹  ์ปค๋ฐ‹์„ ๊ฐ€์ ธ์˜จ๋‹ค.

  2. ๊ฐ์ž ์ž‘์—…ํ•œ ๋’ค, ์ž‘์—… ๋‚ด์—ญ์„ ์›๊ฒฉ ์ €์žฅ์†Œ์— ์ปค๋ฐ‹ํ•˜๊ณ  ํ‘ธ์‹œํ•œ๋‹ค.

    • git add ์ž‘์—…ํŒŒ์ผ.txt
    • git commit -m "์ปค๋ฐ‹๋ฉ”์‹œ์ง€"
    • git push -u origin master

5.4 ํ˜‘์—…์—์„œ ๋ธŒ๋žœ์น˜ ์‚ฌ์šฉํ•˜๊ธฐ

ํ˜‘์—… ์‹œ ํŒ€์›๋“ค์ด ๊ฐ๊ฐ ๋‹ค๋ฅธ ๊ธฐ๋Šฅ์„ ๋งก์•„ ์ž‘์—…ํ•˜๊ฒŒ ๋œ๋‹ค.
๊ฐ ์ž‘์—…์ด master๋ธŒ๋žœ์น˜์˜ ๋ฌธ์„œ์™€ ์„ž์ด์ง€ ์•Š๋„๋ก, ๊ฐœ๋ณ„ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค์–ด ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•ด์•ผ ํ•œ๋‹ค.
๊ฐ ํŒ€์›์ด ๋งŒ๋“  ๋ธŒ๋žœ์น˜ ์—ญ์‹œ ์›๊ฒฉ ์ €์žฅ์†Œ์— ํ‘ธ์‹œํ•  ์ˆ˜ ์žˆ๋‹ค.

๊นƒํ—ˆ๋ธŒ์—์„œ ํ˜‘์—…ํ•  ๋•Œ๋Š” ๋ณดํ†ต ์ž‘์—…์ž๋งˆ๋‹ค ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค์–ด ์ง„ํ–‰ํ•˜๋ฉฐ, ์ž‘์—… ์ค‘๊ฐ„์ค‘๊ฐ„ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ๋ณด๋‚ด master๋ธŒ๋žœ์น˜์— ๋ณ‘ํ•ฉํ•œ๋‹ค.

์ƒˆ ๋ธŒ๋žœ์น˜ ํ‘ธ์‹œ

๋กœ์ปฌ ์ €์žฅ์†Œ์—์„œ ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ๋งŒ๋“ค๊ณ , ์ปค๋ฐ‹ํ•œ ๋‹ค์Œ, ์›๊ฒฉ ์ €์žฅ์†Œ์— ํ‘ธ์‹œํ•œ๋‹ค.

  1. ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ์ตœ์‹  ์ปค๋ฐ‹ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค

    • ํ•ญ์ƒ ํ’€pull๋ถ€ํ„ฐ ํ•œ ๋‹ค์Œ ์ž‘์—…์„ ์ง„ํ–‰ํ•œ๋‹ค.
      ์™œ? ๊นƒํ—ˆ๋ธŒ๋กœ ํ˜‘์—…ํ•  ๋•Œ๋Š” ๋‹ค๋ฅธ ์ž‘์—…์ž์˜ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•ด์•ผ ํ•˜๋ฏ€๋กœ

    • git pull

  2. ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ž‘์—…ํ•  ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ๋กœ์ปฌ ์ €์žฅ์†Œ์— ๋งŒ๋“ค๊ณ , ์ƒˆ ๋ธŒ๋žœ์น˜๋กœ ์ฒดํฌ์•„์›ƒํ•œ๋‹ค.

    • git branch ๋ธŒ๋žœ์น˜๋ช…
      git checkout ๋ธŒ๋žœ์น˜๋ช…
    • ๋˜๋Š” git checkout -b f(๋ธŒ๋žœ์น˜ ๋งŒ๋“ค๊ธฐ + ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ ์ฒดํฌ์•„์›ƒ)
  3. ์ƒˆ ๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—…ํ•œ ๋’ค ์ปค๋ฐ‹

    • git add ์ž‘์—…ํŒŒ์ผ.txt
    • git commit -m "์ปค๋ฐ‹๋ฉ”์‹œ์ง€"
  4. ์›๊ฒฉ ์ €์žฅ์†Œ์— ์ƒˆ ๋ธŒ๋žœ์น˜๋ฅผ ํ•จ๊ป˜ ํ‘ธ์‹œ

    • git push origin ๋ธŒ๋žœ์น˜๋ช…
      : ์›๊ฒฉ ์ €์žฅ์†Œ(origin)์— ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋ฅผ ํ‘ธ์‹œํ•œ๋‹ค.
  5. ๊นƒํ—ˆ๋ธŒ ์›๊ฒฉ ์ €์žฅ์†Œ์— ์ ‘์†ํ•ด ํ‘ธ์‹œํ•œ ๋ธŒ๋žœ์น˜๋ฅผ ํ™•์ธํ•œ๋‹ค.

ํ’€ ๋ฆฌํ€˜์ŠคํŠธ pull request ๋กœ ํ‘ธ์‹œํ•œ ๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉ

์›๊ฒฉ ์ €์žฅ์†Œ์— ํ‘ธ์‹œ๋œ ๋ธŒ๋žœ์น˜๋Š” ํ’€ ๋ฆฌํ€˜์ŠคํŠธ(pull request, PR)๋ฅผ ํ†ตํ•ด ๋ณ‘ํ•ฉ(merge)ํ•ด์•ผ ํ•œ๋‹ค.
๊ทธ๋ž˜์•ผ ํ•ด๋‹น ๋ธŒ๋žœ์น˜์—์„œ ์ž‘์—…ํ•œ ๋‚ด์šฉ์ด ์›๊ฒฉ ์ €์žฅ์†Œ์— ๋ฐ˜์˜๋œ๋‹ค.

ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋Š” ํ•ด๋‹น ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ๊ณต๋™ ์ž‘์—…์ž๋ผ๋ฉด ๋ˆ„๊ตฌ๋‚˜ ์‚ดํŽด๋ณด๊ณ  ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋‹ค.

  1. ์›๊ฒฉ ์ €์žฅ์†Œ์— ํ‘ธ์‹œ๋œ ๋ธŒ๋žœ์น˜ ์˜†์˜ [New pull request]๋ฅผ ๋ˆ„๋ฅธ๋‹ค
  2. pull request ๋ฉ”์‹œ์ง€(์ œ๋ชฉ, ๋‚ด์šฉ)๋ฅผ ์ž‘์„ฑํ•œ ํ›„ [Create pull request]๋ฅผ ๋ˆŒ๋Ÿฌ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ์ „์†กํ•œ๋‹ค
  3. ์›๊ฒฉ์ €์žฅ์†Œ์—์„œ Pull request๋ฅผ ๋ˆŒ๋Ÿฌ ๋“ฑ๋ก๋œ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ ๋ชฉ๋ก์„ ํ™•์ธํ•œ๋‹ค.
  4. ๊ฐ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ ๋ฉ”์‹œ์ง€๋ฅผ ํ™•์ธ ํ›„, ์ž‘์—… ๋‚ด์šฉ์— ๋ฌธ์ œ๊ฐ€ ์—†์œผ๋ฉด [Merge pull request]๋ฅผ ๋ˆ„๋ฅธ๋‹ค
    • ํ•ด๋‹น ๊ณต๊ฐ„์—์„œ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ๋‚จ๊ธด ์‚ฌ๋žŒ๊ณผ ๋ฉ”์‹œ์ง€๋ฅผ ์ฃผ๊ณ ๋ฐ›์„ ์ˆ˜๋„ ์žˆ๋‹ค.
  5. ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜๊ณ  [Confirm merge]๋ฅผ ๋ˆŒ๋Ÿฌ ๋ธŒ๋žœ์น˜๋ฅผ ๋ณ‘ํ•ฉํ•œ๋‹ค.
  6. ๋ธŒ๋žœ์น˜์— ์žˆ๋˜ ํŒŒ์ผ์ด master๋ธŒ๋žœ์น˜์— ์ž˜ ๋ณ‘ํ•ฉ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ๋ธŒ๋žœ์น˜ ๋ชฉ๋ก์„ ๋ˆŒ๋Ÿฌ ๋ธŒ๋žœ์น˜๊ฐ€ ์ž˜ ๋ณ‘ํ•ฉ๋˜์—ˆ๋Š”์ง€ (merged์ƒํƒœ์ธ์ง€) ํ™•์ธํ•œ๋‹ค.