문제 상황
- origianlRemoteRepository에 새로운 branch인 'newBranch'가 추가되었을 때 myLocalRepository에도 해당 branch를 추가해야 하는 상황
- 주어진 저장소
- origianlRemoteRepository: 원본 저장소
- myRemoteRepository: origianlRemoteRepository를 fork한 저장소
- myLocalRepository: myRemoteRepository를 local에 clone한 저장소
해결 방법
-
해결 순서
- myLocalRepository에 새로운 remote 저장소 origianlRemoteRepository를 등록해준다.
- 등록한 origianlRemoteRepository를 fetch한다.
- origianlRemoteRepository의 'newBranch'를 myLocalRepository에 생성한다.
- 생성한 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 확인 후 가져옴