๋ฐ˜์‘ํ˜•

merge ์ถฉ๋Œ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•œ ๋ฆฌ๋ฒ ์ด์Šค(Rebase) โญ๏ธ


PR ๋ณด๋‚ด๊ธฐ ์ „ ๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ์ƒˆ๋กœ์šด ์ปค๋ฐ‹์„ ์ถ”๊ฐ€ํ•œ ์ƒํƒœ๋ผ๋ฉด ์ถฉ๋Œ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ๋กœ์ปฌ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ตœ์‹ ํ™”ํ•˜๊ณ (upstream โ‡„ origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋™๊ธฐํ™”), ํ˜„์žฌ ์ž‘์—…์ค‘์ธ ๊ธฐ๋Šฅ/๋ฒ„๊ทธ ๋ธŒ๋žœ์น˜์˜ base๋ฅผ develop ๋ธŒ๋žœ์น˜์˜ ๋งˆ์ง€๋ง‰ ์ปค๋ฐ‹์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฆฌ๋ฒ ์ด์Šค(Rebase) ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค — ์ฐธ๊ณ ๊ธ€1 | ์ฐธ๊ณ ๊ธ€2

 

โถ ํ˜„์žฌ ์ƒํƒœ

# ํ˜„์žฌ ์œ„์น˜ feature-branch 8๋ฒˆ ์ปค๋ฐ‹
1 - 2 - 3 - 5 (devlop)
     \
      4 - 6 - 7 - 8 (feature-branch)
  • develop ๋ธŒ๋žœ์น˜์˜ 1~2 ์ปค๋ฐ‹ : ๋กœ์ปฌ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ develop ๋ธŒ๋žœ์น˜ ์ปค๋ฐ‹
  • develop ๋ธŒ๋žœ์น˜์˜ 3~5 ์ปค๋ฐ‹ : ์›๊ฒฉ(upstream) ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•œ ์ปค๋ฐ‹
  • feature-branch ๋ธŒ๋žœ์น˜์˜ 4~8 ์ปค๋ฐ‹ : ๋กœ์ปฌ์—์„œ ํ˜„์žฌ ์ž‘์—…์ค‘์ธ ์ปค๋ฐ‹

 

โท develop ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ ํ›„ ์—…์ŠคํŠธ๋ฆผ๊ณผ ๋™๊ธฐํ™” e.g. git pull upstream develop

# ์ตœ์‹ ํ™” ํ›„ ํ˜„์žฌ ์œ„์น˜ develop 5๋ฒˆ ์ปค๋ฐ‹
1 - 2 - 3 - 5 (devlop)
     \
      4 - 6 - 7 - 8 (feature-branch)

 

โธ feature-branch ๋ธŒ๋žœ์น˜๋กœ ์ด๋™ ํ›„ ๋ฆฌ๋ฒ ์ด์Šค e.g. git rebase develop

# ํ˜„์žฌ ์œ„์น˜ feature-branch 8๋ฒˆ ์ปค๋ฐ‹
1 - 2 - 3 - 5 (devlop)
             \
              4 - 6 - 7 - 8 (feature-branch)

 

โน origin/feature-branch๋กœ push e.g. git push origin feature-branch

 

โบ origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ upstream/develop์œผ๋กœ PR

 

์ถฉ๋Œ ์ƒํ™ฉ์—์„œ Rebase


  1. origin/develop ์ตœ์‹ ํ™” (upstream/develop๊ณผ ๋™๊ธฐํ™”)
  2. [๋กœ์ปฌ] git pull origin develop
  3. [๋กœ์ปฌ] feature-branch ์ด๋™ ํ›„ ๋ฆฌ๋ฒ ์ด์Šค e.g. git rebase develop
  4. ์ถฉ๋Œ ํŒŒ์ผ ํ•ด๊ฒฐ
  5. ๋ฆฌ๋ฒ ์ด์Šค ์ง„ํ–‰ e.g. git rebase --continue
  6. origin/feature-branch๋กœ push

 

๐Ÿ’ก ์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ตœ์‹  ๋‚ด์šฉ์„ ๊ฐ€์ ธ์˜ค๋ผ๋Š” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด?

๊ฐ•์ œ push๋กœ ์ง„ํ–‰ํ•˜๋ฉด ๋œ๋‹ค. ๋ฆฌ๋ฒ ์ด์Šค๋Š” ์ปค๋ฐ‹์˜ ๋ณ€๊ฒฝ ์‚ฌํ•ญ(diff)์„ patch๋ผ๋Š” ์ž„์‹œ ์ €์žฅ์†Œ์— ์˜ฎ๊ธด ํ›„, base ๋ธŒ๋žœ์น˜ ๋’ค์— ์ƒˆ๋กœ์šด ์ปค๋ฐ‹์„ ๋งŒ๋“ค๊ณ  patch์— ์ž„์‹œ ์ €์žฅํ•œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ์ ์šฉํ•œ๋‹ค. diff๋Š” ๋™์ผํ•˜์ง€๋งŒ commit hash๊ฐ€ ๋‹ฌ๋ผ์ ธ์„œ pull ํ•˜๋ผ๋Š” ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ.

 

๊ฐ•์ œ push๋Š” --force ์˜ต์…˜์„ ์ฃผ๋ฉด ๋œ๋‹ค. ํ•˜์ง€๋งŒ ๋ฆฌ๋ฒ ์ด์Šคํ•˜๋Š” ๋™์•ˆ ๋ˆ„๊ตฐ๊ฐ€ ์ƒˆ๋กœ์šด commit์„ ์›๊ฒฉ์— ์ถ”๊ฐ€ํ–ˆ๋‹ค๋ฉด ๋ฆฌ๋ฒ ์ด์Šค ๋ฒ„์ „์„ ์›๊ฒฉ ๋ฒ„์ „์— ๋ฎ์–ด์“ฐ๋ฏ€๋กœ ์ƒˆ๋กœ์šด ์ปค๋ฐ‹์€ ์‚ฌ๋ผ์ง„๋‹ค.

 

์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋ฆฌ๋ฒ ์ด์Šคํ•œ ๋ฒ„์ „๊ณผ ์›๊ฒฉ ๋ฒ„์ „์ด ๋™์ผํ•  ๋•Œ๋งŒ(์›๊ฒฉ์— ์ƒˆ๋กœ์šด ์ปค๋ฐ‹์ด ์—†์„๋•Œ๋งŒ) ๊ฐ•์ œ push๋ฅผ ์ง„ํ–‰ํ•˜๋Š” --force-with-lease ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์ข‹๋‹ค.

 

e.g. git push origin feature-branch --force-with-lease

 

๋กœ์ปฌ ๋ธŒ๋žœ์น˜ ์ตœ์‹ ํ™” ์ฐธ๊ณ 


upstream โ‡„ origin sync (์ฐธ๊ณ  ๋ฌธ์„œ)

  1. ํ„ฐ๋ฏธ๋„ ์‚ฌ์šฉ ์‹œ
    • local์—์„œ upstream fetch : e.g. git fetch upstream
    • local์—์„œ ๊ฐ€์žฅ ์ตœ์‹  commit์œผ๋กœ checkout : e.g. git checkout develop
    • upstream ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ํ˜„์žฌ ๋ธŒ๋žœ์น˜์— merge : e.g. git merge upstream/develop
    • local ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ push : e.g. git push origin develop
  2. GitHub CLI ์‚ฌ์šฉ์‹œ
    • fetch ๋ฐ merge : e.g. gh repo sync owner/cli-fork
    • local ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ origin ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋กœ push

 

์›๊ฒฉ ์ €์žฅ์†Œ์˜ ์ƒ์„ธ ์ •๋ณด ํ™•์ธ

git remote show origin

๋ฐ˜์‘ํ˜•