Single branch로 Clone 후, 새로운 브랜치 추가

Solar·2020년 2월 8일
0

버전관리시스템

목록 보기
3/4

git에서 브랜치가 너무 많아 특정 브랜치만 추적하도록 clone할 수 있다.

git clone -b <branch name> --single-branch <github url> <target directory>

위와 같이 clone한 후 새로운 브랜치를 추가하고 싶은 경우가 있으면 다음과 같이 새로운 브랜치를 추가할 수 있다.

git remote set-branches --add origin [remote-branch]
git fetch origin [remote-branch]:[local-branch]
  1. 싱글 브랜치로 다시 생성
git clone -b blossun --single-branch https://github.com/blossun/java-monster-race

  1. origin/step2 브랜치도 보이도록 추가
git checkout blossun
git branch -d step2
git fetch origin step2:step2

origin/step2 브랜치도 보이는 것을 확인할 수 있다.

참고

git을 single branch로 clone한 후 새로운 브랜츠를 추가하고 싶은 경우

profile
nunnu

2개의 댓글

comment-user-thumbnail
2020년 10월 29일

솔라

git fetch origin step2:: << 요거 step2

저기 콜론이 1개만 들어가야 하는데 2개 들어간 걸로 오타났어!

git fetch origin step2::step2
fatal: invalid refspec 'step2::step2'

나 망한 줄 알고 식겁했어 진짜🤣

1개의 답글