failed to push some refs 와 non-fast-forward 는
원격 저장소 쪽이 내 로컬보다 앞서 있어서 그대로 push 할 수 없을 때 발생한다.
즉, 다른 사람이 먼저 push 했거나, GitHub에서 직접 수정된 commit이 있어서 내 기록만 바로 올릴 수 없는 상태이다.
git push origin main
To github.com:user/repo.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'git@github.com:user/repo.git'
hint: Updates were rejected because the tip of your current branch is behind보통 아래 경우이다.
- 다른 사람이 먼저 push 함
- GitHub 웹에서 README 등을 수정함
- 다른 PC에서 작업 후 이미 push 함
- 로컬 branch가 원격보다 뒤처짐
git fetchgit log --oneline --graph --allgit status원격 내용을 먼저 반영한 뒤 다시 push 한다.
git pull origin main
git push origin maingit pull 과정에서 conflict가 나면 직접 해결해야 한다.
git status
git add .
git commit -m "MERGE: resolve conflict"
git push origin main히스토리를 깔끔하게 이어붙이고 싶으면 rebase 방식도 쓴다.
git pull --rebase origin main
git push origin maingit add .
git rebase --continuegit push --force origin main이 명령은 원격 기록을 덮어쓸 수 있으므로 협업 중에는 매우 조심해야 한다.
이 에러는
원격 저장소에 내 로컬에 없는 최신 commit이 있어서 바로 push 할 수 없는 상태이다.