git push 했는데 ! [rejected] main -> main (fetch first)나 (non-fast-forward)가 나오면, 원격 저장소에 내 컴퓨터에 없는 커밋이 먼저 올라가 있다는 뜻입니다. 대부분은 아래 두 줄로 끝납니다.
git pull --rebase origin main
git push origin main
git push --force는 남이 올린 커밋을 지워 버릴 수 있어서 마지막 수단입니다. 아래 내용은 2026년 11월 20일 리눅스에서 git 2.43.0으로 원격 저장소 하나에 두 사람이 번갈아 push 하는 상황을 직접 만들어 확인한 결과입니다.
1. 오류 원문 두 가지
A가 커밋한 사이에 B가 먼저 push 하면, A의 push는 이렇게 거절됩니다.
! [rejected] main -> main (fetch first)
error: failed to push some refs to '…/remote.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref.
A가 git fetch로 원격 상태를 받아 온 뒤 다시 push 하면 괄호 안 글자만 바뀝니다.
! [rejected] main -> main (non-fast-forward)
hint: Updates were rejected because the tip of your current branch is behind
둘 다 원인은 같습니다. 원격 main에는 B의 커밋이 있고, 내 main에는 내 커밋이 있어서 두 갈래로 갈라진 상태입니다. git은 갈라진 상태에서 원격 커밋을 덮어쓰지 않으려고 push를 막습니다.
2. 그냥 git pull 하면 또 막히는 이유
요즘 git(이번에 쓴 2.43.0 포함)은 설정 없이 git pull을 하면 합치는 방법을 정하라고 멈춥니다. 직접 실행했을 때 나온 메시지입니다.
hint: You have divergent branches and need to specify how to reconcile them.
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
fatal: Need to specify how to reconcile divergent branches.
그래서 처음부터 방법을 붙여서 pull 하는 게 편합니다.
3. 해결 1: pull --rebase (아직 push 안 한 내 커밋일 때 추천)
git pull --rebase origin main
git push origin main
실행 결과 Successfully rebased and updated refs/heads/main.이 나오고, 기록이 한 줄로 정리됐습니다. 원격 커밋(c2) 위에 내 커밋(c3)이 올라간 모양입니다.
* 9dcf457 c3
* 877020c c2
* f65d92c c1
그다음 push는 877020c..9dcf457 main -> main으로 정상 반영됐습니다.
4. 해결 2: merge로 합치기
기록을 고치지 않고 "합친 커밋"을 남기고 싶으면 git pull --no-rebase origin main을 씁니다. rebase가 낯설거나 팀 규칙이 merge라면 이쪽을 쓰세요. 매번 고르기 귀찮으면 git config --global pull.rebase true(또는 false)로 기본값을 정해 두면 됩니다.
5. 같은 줄을 둘 다 고쳤을 때 (충돌)
A와 B가 같은 파일의 같은 줄을 고친 상태에서 git pull --rebase를 하면 이렇게 멈춥니다.
error: could not apply eff6c0f... aconf
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
git status에서UU로 표시된 파일을 열고<<<<<<<~>>>>>>>부분을 원하는 내용으로 고칩니다.git add 파일이름git rebase --continue(모르겠으면git rebase --abort로 pull 전 상태로 돌아갈 수 있습니다)git push origin main
직접 해 보니 위 순서대로 Successfully rebased 후 push가 됐습니다.
6. --force는 언제 쓰나
git push --force는 원격에 있는 남의 커밋을 내 기록으로 덮어씁니다. 혼자 쓰는 브랜치에서 git commit --amend나 rebase로 이미 올린 커밋을 고친 경우에만 쓰고, 그때도 git push --force-with-lease를 권합니다. 내가 마지막으로 받아 온 뒤 원격이 바뀌었으면 덮어쓰지 않고 거절해 주기 때문입니다(공식 문서 설명).
7. 한눈에 정리
| 상황 | 명령 |
|---|---|
| push가 fetch first / non-fast-forward로 거절 | git pull --rebase origin main 후 push |
| pull이 divergent branches로 멈춤 | --rebase 또는 --no-rebase를 붙이거나 pull.rebase 설정 |
| rebase 중 충돌 | 파일 수정 → git add → git rebase --continue |
| 그만두고 싶을 때 | git rebase --abort |
| 내가 올린 커밋을 고쳐서 다시 올릴 때 | git push --force-with-lease (공용 브랜치에는 쓰지 않기) |
실행 환경: 리눅스, git 2.43.0, 로컬 bare 저장소로 GitHub 원격을 흉내 냄. 윈도우·맥과 GitHub 화면에서는 직접 실행하지 않았습니다. 초안 작성과 검수에 AI를 사용했고, 명령과 출력은 직접 실행해 대조했습니다.
기준일: 2026-11-20
출처
- git-push 문서 (NOTE ABOUT FAST-FORWARDS, --force-with-lease): https://git-scm.com/docs/git-push
- git-pull 문서 (--rebase, pull.rebase): https://git-scm.com/docs/git-pull
'개발 오류 해결' 카테고리의 다른 글
| git push Permission denied (publickey) 해결: SSH 키·HTTPS (0) | 2026.11.20 |
|---|---|
| pip externally-managed-environment 오류 해결: venv·pipx 정리 (0) | 2026.11.19 |
| 압축 풀면 한글 파일명 깨짐 해결: 맥·윈도우 zip 원인 3가지와 바로 푸는 법 (0) | 2026.11.18 |
| git 한글 파일명 깨짐 해결: 숫자로 나올 때 core.quotepath, 맥 자소 분리까지 (0) | 2026.11.17 |
| 파이썬 'cp949' codec can't decode 오류 해결: 한글 깨짐 5가지 경우와 파이썬 3.15에서 달라진 점 (0) | 2026.11.16 |