Dechive Logo
Dechive
← Logs
#git#github-actions#submodule#workflow

git push rejected (fetch first) — GitHub Actions 봇이 먼저 커밋해서 push가 막힐 때

로컬에서 push하려는데 봇이 먼저 커밋해놔서 rejected. git pull --rebase 한 방으로 해결.

에러 메시지

! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/Aprasaks/dechive-content.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

원인

content 서브모듈에 .ko.md 포스트를 push하면 GitHub Actions 번역 봇이 자동으로 실행된다. 봇은 .en.md 영어 번역본을 생성해 원격 저장소에 직접 커밋한다.

그 상태에서 로컬에서 추가 push를 시도하면, 원격에 로컬이 모르는 커밋(봇 커밋)이 생겨 rejected가 발생한다.

로컬:  A → B (내 커밋)
원격:  A → B → C (봇의 .en.md 커밋)
           ↑ 여기서 diverge

해결법

git pull --rebase origin main && git push

--rebase를 쓰면 봇 커밋 위에 내 커밋을 얹어서 히스토리가 깔끔하게 유지된다. merge commit이 생기지 않는다.

언제 이게 뜨냐

두 경우 모두 위 한 줄로 해결된다.

서브모듈 전체 워크플로우

# 1. content 서브모듈에서 포스트 작성 후
cd content
git add . && git commit -m "feat: 포스트 제목" && git push

# → 봇이 .en.md 자동 생성해서 push함

# 2. 이후 추가 수정이 있으면
git pull --rebase origin main && git push

# 3. 메인 레포에서 서브모듈 포인터 업데이트
cd ..
git add content && git commit -m "chore: content 서브모듈 업데이트 [...]"
git pull --rebase origin main && git push

메인 레포 push 시에도 같은 이유로 rejected가 뜰 수 있다. 동일하게 git pull --rebase origin main && git push로 해결한다.

사서Dechive 사서