리눅스
git clone 특정 디렉토리만 선택적으로 복제하는 방법
변군이글루
2024. 6. 19. 19:25
반응형
git clone 특정 디렉토리만 선택적으로 복제하는 방법
git clone 명령어는 전체 저장소를 복제하는 데 사용되며 특정 디렉토리만 선택적으로 복제하는 기능은 지원하지 않습니다. 하지만 특정 디렉토리만 가져오는 비슷한 효과를 낼 수 있습니다.
git 버전 확인
git version
$ git version
git version 2.34.1
Partial Clone
Git 2.19 이상에서 지원하는 기능으로 필요한 파일만 다운로드할 수 있습니다. 하지만 특정 디렉토리만 클론하는 것과는 조금 다릅니다.
git clone --filter=blob:none --no-checkout <repository-url>
cd <repository-directory>
git sparse-checkout init --cone
git sparse-checkout set <directory-path>
git checkout <branch>
예를 들어, src 디렉토리만 클론하려면 다음과 같이 합니다.
git clone --filter=blob:none --no-checkout https://github.com/user/repo.git
cd repo
git sparse-checkout init --cone
git sparse-checkout set src
git checkout main
728x90
Sparse Checkout
Sparse Checkout 기능을 사용하면 특정 디렉토리만 체크아웃할 수 있습니다.
git clone --no-checkout <repository-url>
cd <repository-directory>
git config core.sparseCheckout true
echo "<directory-path>/" >> .git/info/sparse-checkout
git checkout <branch>
예를 들어, src 디렉토리만 체크아웃하고 싶다면 다음과 같이 할 수 있습니다.
git clone --no-checkout https://github.com/user/repo.git
cd repo
git config core.sparseCheckout true
echo "src/" >> .git/info/sparse-checkout
git checkout main
이 방법들을 통해 필요한 디렉토리나 파일만 가져오는 효과를 낼 수 있습니다.
참고URL
- git-scm.com : partial-clone
- git-scm.com : git-sparse-checkout
728x90
반응형