Search

git pull 시 merge, rebase, ff-only의 차이

힌트: You have divergent branches and need to specify how to reconcile them. 힌트: You can do so by running one of the following commands sometime before 힌트: your next pull: 힌트: 힌트: git config pull.rebase false # merge 힌트: git config pull.rebase true # rebase 힌트: git config pull.ff only # fast-forward only 힌트: 힌트: You can replace "git config" with "git config --global" to set a default 힌트: preference for all repositories. You can also pass --rebase, --no-rebase, 힌트: or --ff-only on the command line to override the configured default per 힌트: invocation. fatal: Need to specify how to reconcile divergent branches.
JavaScript
복사

1. git config pull.rebase false → merge 방식

• 기본적으로 Git은 git pull을 하면 merge 방식을 사용해.
• 즉, 로컬 브랜치와 원격 브랜치가 다르면 자동으로 merge commit을 생성해.
로컬 변경 사항 + 원격 변경 사항을 합치고, 새 커밋이 하나 더 생김.
• 일반적으로 협업할 때 자동으로 병합하는 방식으로 많이 사용돼.
// 원격 main A -- B -- C // 로컬 main A -- B -- D // 로컬에서 새 커밋 추가 // git pull 실행 후 결과 A -- B -- C -- D -- M // (M: merge commit)
JavaScript
복사
장점: 협업 중 여러 명이 작업할 때 충돌을 최소화할 수 있음.
단점: git log가 지저분해질 수 있음.

2. git config pull.rebase true → rebase 방식

• rebase 방식은 로컬 변경 사항을 임시로 빼놓았다가 원격 변경 사항을 먼저 적용한 후 다시 적용하는 방식이야.
• 즉, 로컬에서 작업한 커밋을 원격 커밋 위로 다시 쌓는 것이야.
병합 커밋(merge commit)이 생기지 않아서 git log가 더 깔끔함.
// 원격 main A -- B -- C // 로컬 main A -- B -- D // 로컬에서 새 커밋 추가 // git pull 실행 후 결과 A -- B -- C -- D // D 커밋이 원격 C 뒤에 정렬됨
JavaScript
복사
장점: git log가 깔끔하게 정리됨.
단점: 이미 원격에 푸시된 커밋을 rebase하면 강제 푸시 (git push -f)가 필요할 수 있음.

3. git config pull.ff only → fast-forward only 방식

원격 변경 사항이 로컬 브랜치보다 앞서 있을 때만 병합을 허용하는 방식이야.
• 만약 로컬에서 따로 작업한 커밋이 있으면 pull을 거부함.
// 원격 main A -- B -- C // 로컬 main A -- B // git pull 실행 후 결과 A -- B -- C -- D // 원격과 동일하게 업데이트 됨
JavaScript
복사
// 원격 main A -- B -- C // 로컬 main A -- B -- D // git pull 실행 후 결과 error: Not possible to fast-forward, aborting.
JavaScript
복사
장점: 충돌을 피할 수 있음.
단점: 협업 중에는 거의 사용되지 않음.