[git] 레포지토리 내 특정폴더만 git clone 받기

클론 폴더 경로 생성

mkdir "폴더 이름"
cd "폴더 이름"

 

Git 저장소 초기화

git init

 

(1)에서 생성한 디렉토리를 git 저장소로 변환

 

Sparse Checkout 기능 활성화

git config core.sparseCheckout true

 

= git 저장소에서 특정 파일이나 디렉토리만을 선택적으로 체크아웃 할 수 있도록 해줌

 

 

Remote Repository 연결

git remote add -f origin "remote repository url"

 

 

Git Checkout

echo "remote repository 폴더 경로" >> .git/info/sparse-checkout

 

해당 폴더 경로만을 따와 sparse checkout을 진행해줍니다.

 

Git Pull

git pull origin main

 

이제 원격 브랜치의 내용을 pull 받으면 끝!

 

 

 


Sparse-Checkout 초기화

sparse-checkout을 초기화 하여 처음부터 다시하고 싶다면 아래 방법을 따릅니다.

 

sparse-checkout 초기화

git sparse-checkout init

 

sparse-checkout 경로 설정

git sparse-checkout set "체크아웃 경로"

 

remote repository의 master 브랜치 트리 구조 확인

git ls-tree -r --name-only origin/master(main)

'기타 등등 > Git' 카테고리의 다른 글

[git] 깃 따라하기 1 / git repository 연결  (1) 2024.04.17