C.W.K.
Stream
Lesson 03 of 05 · published

Rebase vs Merge

~22 min · rebase, merge

Level 0Untracked 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Rebase vs merge: 모양과 의도

둘 다 한 branch 의 작업을 다른 branch 로 통합. 차이는 history 에 무슨 짓을 하느냐. Merge 는 두 parent 가진 새 commit 으로 두 history 를 Y-junction 에서 합침 — 두 line 다 graph 에 visible. Rebase 는 source branch commit 을 target tip 위에 새 commit 으로 replay — 결과는 merge commit 없는 단일 선형 chain. 같은 content, 아주 다른 모양.

실용적 결정 트리. Merge 써 — 발산이 의미 있을 때: 장기 release branch 통합, 기능 완성을 작업 단위로 표시, compliance 용 '어디서 왔는지' audit trail 보존. Rebase 써 — 발산이 우연일 때: 짧은 feature branch — 그 commit 들은 main 에 'merge of main into feature/x' 같은 noise 추가. 매일 ship 하는 대부분 제품 팀엔 feature branch 에 rebase 가 승 — main 이 tangle 이 아니라 기능들의 단일 시퀀스로 읽혀.

팀 정책 형태: 셋 중 하나 선택. (a) 선형 history — 모든 PR 이 main 에 rebase + fast-forward merge, main 은 한 chain. (b) 항상 merge — 모든 PR 이 fast-forward 가능해도 merge commit 생성 (--no-ff), main 에 visible feature 단위. (c) Merge 시 squash — 모든 PR commit 이 main 에 1 commit 으로 collapse, 내부 구조 무관. 각자 내적으로 일관됨. 섞는 게 진짜 문제.

실전 명령 둘. git rebase main 을 feature branch 에서 = local commit 을 main 의 현재 tip 에 replay. Conflict 는 interactive mode 처럼 rebase 를 일시정지, 해결 후 git rebase --continue. git rebase --onto <new-base> <old-base> <branch> 는 branch 를 한 base 에서 다른 base 로 이동 — 처음에 잘못된 곳에서 분기했을 때 유용.

Code

두 통합 모양·bash
# Feature 를 현재 main 에 rebase:
git switch feature/x
git fetch origin
git rebase origin/main

# 결과: feature/x 의 commit 들이 origin/main 위에 선형으로 자리.

# Merge 대신:
git switch main
git merge feature/x          # 가능하면 FF, 아니면 three-way
git merge --no-ff feature/x  # 항상 merge commit 생성
Rebase --onto 로 정밀 re-parenting·bash
# feature/email-templates 를 feature/auth 에서 분기했는데
# feature/auth 가 폐기될 예정. email-templates 를 main 위에
# 살게 하고 싶다.

git rebase --onto main feature/auth feature/email-templates

# 해석: "feature/email-templates 의 feature/auth 이후 commit 을
# main 에 replay, 옛 base 교체."

External links

Exercise

같은 baseline 에서 시작하는 scratch repo 둘. 하나엔 feature branch 끝낸 후 git merge --no-ff 로 통합. 다른 거엔 git rebase main 후 fast-forward merge 로 통합. 각자 git log --oneline --graph --all 실행. 모양 비교. 6개월 뒤 어느 게 읽기 더 좋을지 결정 + 한 줄로 이유.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.