[Git] fatal: Not possible to fast-forward, aborting.

seohyun Kang·2023년 9월 20일

Introduction

Commit을 리모트 Branch에 푸시하고 해당 커밋을 revert한 뒤에 다른 커밋을 생성 했더니 브랜치의 형태가 아래와 같아졌습니다.

이후, 로컬 브랜치를 리모트에 푸시하려고 하자 아래와 같은 에러가 발생합니다.

![rejected] ${branchName} -> ${branchName} (non-fast-forward)
error: failed to push some refs to 'remote url'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

에러 메세지를 확인하고 git pull을 요청하니까

fatal: Not possible to fast-forward, aborting.

이러한 에러가 발생했습니다.

.git/configgit pull cmd 에 대하여 아래와 같이 fast-forward 옵션을 사용하는 것으로 설정되어있었습니다.

[pull]
        ff = only
        rebase = false

Default로 설정된 fast-forward에서는 위와 같이 서로 다른 commit이 존재하는 경우, git pull cmd가 실패하게 되고 --rebase 혹은 --no-ff flag를 사용하여 git pull을 요청해야합니다.

그렇다면, ff(fast-forward), rebase의 의미에 대해서 확인하려고 합니다.

Fast-forward란?

Fast-forward = 빨리 감기

현재 브랜치의 커밋 히스토리는 remote/HEAD > commit > local/HEAD로 현재 브랜치가 이전 브랜치(리모트 브랜치)의 commit 히스토리를 가지고 있는 경우를 Fast-forward라고 합니다.

이 경우, pull 혹은 merge를 요청하면 remote/HEAD를 local/HEAD로 옮기게(Fast-forward)됩니다.

Fast-forward가 가능한 경우는 작업 브랜치를 리모트로 옮기면서 이전 커밋의 히스토리를 모두 가지고 있기 때문에 가능하다면, 만약 히스토리를 갖지 않는 경우를 확인하려고 합니다.

Rebase란?

local/HEAD는 remote/HEAD의 commit 히스토리를 갖고 있지 않습니다. 이 경우, remote로 push를 요청하면 pull을 해서 local 브랜치 최신화를 요구하고, --ff 옵션으로 pull을 요청하게 되면 에러가 발생하고 merge를 요청하면 merge commit(Merge branch '$localBranchName' into $remoteBranchName)이 생성됩니다.

이러한 상황에서 rebase를 통해서 문제를 해결할 수 있습니다.

0개의 댓글