원격 저장소 특정 하위 폴더만 클론 git subdirectory clone

jyleever·2022년 9월 17일
0

git

목록 보기
1/3
post-thumbnail

graphQL 레포지토리(https://github.com/siyoon210/spring-framework/tree/master/graphql/baeldung-example)를 클론하려고 하는데 해당 상위 리포지토리에는 내가 필요하지 않은 내용이 많았다. 따라서 특정 하위 폴더만 clone하는 방법을 찾아보았다.

  1. clone 할 로컬 저장소 생성
git init graphQLProj
cd graphQLProj
  1. 기본적으로 clone 하면 모든 폴더가 복제됨. 그러나 git 1.7부터 추가된 sparse checkout 기능을 사용하면 원하는 디렉터리의 파일만 가져올 수 있다.
    따라서 sparse check 가 가능하도록 config를 수정한다.
git config core.sparseCheckout true
  1. remote add
git remote add -f origin https://github.com/siyoon210/spring-framework.git
  1. checkout 하기 원하는 파일 및 폴더를 .git/info/sparse-checkout 파일에 작성(폴더일 경우 자동으로 하위 폴더가 포함됨)
echo "graphql/baeldung-example" >> .git/info/sparse-checkout

  1. 원격 저장소에서 파일을 pull했을 때 sparse-checkout 에 기술한 경로의 파일만 가져온다.
git pull origin master

  1. 파일 확인


참고

https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository
https://earth-95.tistory.com/92
https://www.lesstif.com/gitbook/git-clone-20776761.html

0개의 댓글