Git

중급 05. Push Rejected (Non-fast-forward) 실무 해결 가이드

git push 시 rejected 에러가 발생하는 원인과, 동료의 작업을 덮어쓰지 않고 안전하게 최신화하여 푸시하는 실무 대처법

· 1min read · 3 views
중급 05. Push Rejected (Non-fast-forward) 실무 해결 가이드

핵심 요약

git push 거절(non-fast-forward) 에러 발생 원인, 강제 푸시(-f)로 인한 동료 작업 유실 방지 및 pull --rebase를 통한 안전한 동기화 3단계

기분 좋게 기능 개발을 마치고 git push를 날렸는데, 빨간색 에러 메시지와 함께 푸시가 거절(Rejected)된 적이 있으실 겁니다. 프롬프트 상의 브랜치 표시(branch-name) $를 명시하여 안전하게 동기화하고 푸시하는 3단계를 설명합니다.


1. 어떤 에러 메시지가 발생하는가?

(develop) $ git push origin develop

To https://github.com/my-org/project.git
 ! [rejected]        develop -> develop (non-fast-forward)
error: failed to push some refs to 'https://github.com/my-org/project.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart.

2. 올바른 실무 해결 3단계 (Step-by-Step)

Step 1. 상대방이 무엇을 올렸는지 먼저 확인하기

# 원격의 최신 변경사항 메타데이터만 우선 가져옴 (코드 병합은 아직 안 됨)
(develop) $ git fetch origin develop

# 내 로컬 커밋과 원격 최신 커밋의 차이점 로그 확인
(develop) $ git log HEAD..origin/develop --oneline

Step 2. 원격 커밋을 내 로컬에 안전하게 이어 붙이기 (Rebase Pull)

(develop) $ git pull --rebase origin develop
Successfully rebased and updated refs/heads/develop.

Step 3. 다시 안전하게 원격 푸시하기

(develop) $ git push origin develop
To https://github.com/my-org/project.git
   d1e2f3a..b4c5d6e  develop -> develop

Related Docs

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment

로그인 후 댓글을 남길 수 있습니다.