[git] fork한 래포를 최신으로 동기화

최승언·2023년 1월 8일
0

git

목록 보기
18/27

fork한 내 래포에 최신화된 원본으로 수정하고 싶을 때

0. 현재 remote 확인

현재 fork한 내 래포로 가서 git remote -v 명령어로 현재 remote를 확인한다.

origin  https://gitlab.com/choiseungun/haru.git (fetch)
origin  https://gitlab.com/choiseungun/haru.git (push)

여기서 만약 원본의 remote가 없다면 추가하고 확인한다.

git remote add <최신코드가 있는 remote> <최신코드가 저장소 url>
git fetch <최신코드가 있는 remote> # 생성한 remote로 이동
git remote -v

origin https://gitlab.com/choiseungun/haru.git (fetch)
origin https://gitlab.com/choiseungun/haru.git (push)
main-origin https://gitlab.com/nicreal/haru.git (fetch)
main-origin https://gitlab.com/nicreal/haru.git (push)

1. branch 이동

가져올 branch가 main이면 상관없지만 따로 받고싶은 branch가 있다면 checkout으로 branch를 이용한다.

git checkout <branch >
# ex) git checkout main

2. merge

최신코드를 merge한다. 이 때 원본 origin의 branch는 main이라 가정한다.

git merge <최신코드가 있는 remote>/<최신코드가 있는 branch>
# ex) git merge main-origin/main

3. fetch

다시 원래 사용하던 remote로 이동

git fetch <원래 사용하던 remote>
git remote -v

4. push

push 명령어로 fork된 래포를 업데이트 한다.

git push <원래 사용하던 remote> <원래 사용하던 branch>
profile
작업하다가 막힌부분을 기록하는 곳.

0개의 댓글