본문 바로가기
웹 스터디노트/react(&작심삼주)

[git] 특정 브랜치 하나만 clone 하는 방법

by 미니토이 2024. 5. 27.
--single-branch

 

git에서 특정 Branch 하나만 clone받으려면, -branch 옵션을 사용하여 클론할 수 있다.

이 방법은 해당 브랜치와 그 브랜치에 필요한 히스토리만 다운로드하게 된다.

// git 클론 명령어
git clone -b <branch name> --single-branch <git URL>


// ex. (designBranch라는 이름의 브랜치를 받는 경우)
git clone -b designBranch --single-branch https://github.com/user/repo.git

 

 

 

Sparse Checkout

 

리포지토리를 클론한 후 필요한 브랜치만 체크하는 방법으로

조금 복잡하지만 특정 디렉토리 구조만 필요할 때 유용하다.

git clone <git url>
cd <repository-directory>
git sparse-checkout init --cone
git sparse-checkout set <directory>
git checkout <branch-name>



// ex. repo.git에 designBranch디렉토리만 필요한 경우

git clone https://github.com/user/repo.git
cd repo
git sparse-checkout init --cone
git sparse-checkout set designBranch
git checkout feature-branch

 

 

 


 

 

 

이번 프로젝트는 git branch를 working / staging / main 브랜치로 나누어

작업을 진행할 예정이라고 함.

 

나는 working브랜치만 사용할 것이기에, 

굳이 다른 브랜치까지 가져와서 작업을 하지는 않을 것으로 생각

 

 

 

 

 

아래 첫번째 방법 및 잘 나와있었음.

https://www.slipp.net/questions/605

 

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

git에서 브랜치가 너무 많아 특정 브랜치만 추적하도록 clone할 수 있다. git clone -b --single-branch 위와 같이 clone한 후 새로운 브랜치를 추가하고 싶은 경우가 있으면 다음과 같이 새로운 브랜치를 추

www.slipp.net

 

728x90
반응형

댓글