ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Github] 만약 내 Pull Request가 Merge 되기 전, 누가 Main에 push를 한다면?
    Github 2025. 1. 13. 20:57

    📌 문제 상황

    내가 기능 구현을 한 후 Pull Request를 올려둔 상태에서 팀원들에게 코드 리뷰를 요청한 상태
    그런데, 다른 팀원이 내 Pull Request가 main에 Merge 되기 전, main에 바로 변경 사항을 push한 상황
    그 상황에서 내가 수정사항이 생겨 변경사항을 commit을 해둔 상태라면?

     

    마지막 줄에서 push를 하려고 하면 이때는 충돌이 발생할 수 있어서 push가 불가능하다.

    push를 하면 다음과 같은 메세지가 뜬다.

    * branch main -> FETCH_HEAD 226c0f8..b86eea2 main -> origin/main
    hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches.

     

    이때 콘솔에서는 다음과 같은 방법을 추천한다.

    1. git pull --no-rebase origin main
    // 병합: 기본 병합 방식으로, 충돌 발생하면 직접 해결 후 커밋

    2. git pull --rebase origin main
    // 리베이스: Pull Request 브랜치의 커밋들을 main 브랜치 뒤로 재배치(기록 깔끔하지만, 충돌 가능)

    3. git pull --ff-only origin main
    // Fast-Forward만 허용: 병합할 때 커밋 히스토리가 충돌 없이 직선적으로 이어질 경우에만 업데이트

     

    내가 사용한 방법은 다음과 같다.

    git pull --no-rebase origin main

     

    왜냐하면, 우리 레포지터리는 다음과 같이 구성되어 있기 때문이다.

    AI와 BE, FE 작업 폴더가 나누어져 있다. 이 중에서 내가 사용하는 파일은 FE 폴더에 속하고 팀원이 수정한 파일은 README.md였다. 충돌이 발생할 일이 없었기 때문에 선택한 방법이었다.

     

    해당 명령어를 친 후 Merge 메세지가 나와서 터미널에서 :wq를 입력하여 vi 편집기를 저장 후 닫았다.

    그리고 push를 하면 충돌없이 해결 완료 !!

Designed by Tistory.