Let's Run Jinyeah

Git Push 실패 - Pull & Fetch & Merge 본문

Programming/Git&Github

Git Push 실패 - Pull & Fetch & Merge

jinyeah 2021. 2. 11. 15:53

Error - failed to push some refs to <remote github>

  • remote repository(github)에 나의 local repository에 없는 commit이 존재

  • 팀원이 github에 새로운 수정사항을 반영한 경우
C:\mirror>git push -u origin main
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to <remote github>
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.

 

해결 - pull or (fetch & merge)

  • git pull - remote repository의 내용을 working directory에 반영

    • remote repository내용을 가져와 자동으로 merge까지 한다.

  • get fetch - remote repository의 내용을 local repository에 반영

    • 단순히 remote repository의 내용을 확인만 하고 로컬 저장소와 병합은 하지 않는다.

    • fetch 결과는 remote pository의 최신 커밋을 이름 없는 브랜치(FETCH_HEAD)로 가져온다.

    • git merge를 통해 branch들 간의 내용을 결합

git pull origin main

# fatal: refusing to merge unrelated histories
git pull origin main --allow-unrelated-histories

'Programming > Git&Github' 카테고리의 다른 글

로컬 저장소를 새로운 Github 저장소에 등록  (0) 2021.02.11
Git Merge 충돌 해결 단계  (0) 2021.02.11
Git reset & checkout & ignore  (0) 2020.02.03
Git Branch & Merge  (0) 2020.02.03
Git add & commit & push & 상태확인  (2) 2020.01.10
Comments