Github 다른 원격 저장소의 브랜치를 local 저장소에 브랜치 등록 전략

주성천·2023년 11월 30일

문제 상황


  • origianlRemoteRepository에 새로운 branch인 'newBranch'가 추가되었을 때 myLocalRepository에도 해당 branch를 추가해야 하는 상황
  • 주어진 저장소
      1. origianlRemoteRepository: 원본 저장소
      1. myRemoteRepository: origianlRemoteRepository를 fork한 저장소
      1. myLocalRepository: myRemoteRepository를 local에 clone한 저장소

해결 방법


  • 해결 순서

    1. myLocalRepository에 새로운 remote 저장소 origianlRemoteRepository를 등록해준다.
    2. 등록한 origianlRemoteRepository를 fetch한다.
    3. origianlRemoteRepository의 'newBranch'를 myLocalRepository에 생성한다.
    4. 생성한 branch를 myRemoteRepository에 push한다.
  • 코드

// origianlRemoteRepository를 local에 등록할 때 이름을 'upstream'이라고 할 경우

1. git remote add [upstream] [origianlRemoteRepository]
2. git fetch [upstream]
3. git checkout -b [newBranch] [upstream/newBranch]
4. git push origin newBranch

fetch, pull 차이

fetch vs pull
fetch: local repository에서 remote repository의 최신 meta data 확인
pull: local repository에서 remote repository의 최신 meta data 확인 후 가져옴

profile
기록과 정리

0개의 댓글