/
git 하위 디렉터리, 폴더만 클론(clone) 하기

git 하위 디렉터리, 폴더만 클론(clone) 하기

git 저장소의 my-proj 라는 프로젝트내 폴더 구조가 다음과 같다.

  • src
    • main
      • java
    • test
      • java
  • docs
  • script
    • sys-script
      • config
    • user-script
      • user1

다른 서버에서 이 프로젝트의 sys-script  하위 폴더, user-script/user1과 하위 폴더만  필요하다. 기본적으로 clone 하면 모든 폴더가 복제되지만 git 1.7부터 추가된 sparse checkout 이라는 기능을 사용하면 원하는 경로의 디렉터리나 파일만 복제할 수 있다.


  1. clone 할 로컬 저장소를 만든다.

    git init my-proj
    cd my-proj
  2. sparse Checkout 이 가능하도록 설정한다.

    git config core.sparseCheckout true
  3. remote 를 추가한다.

    git remote add -f origin <REMOTE_URL>
  4. checkout 하기 원하는 파일이나 폴더를 .git/info/sparse-checkout 파일에 기술하면 된다. 폴더일 경우 자동으로 하위 폴더가 포함된다.

    echo "script/sys-script" >> .git/info/sparse-checkout
    echo "script/user-script/user1" >> .git/info/sparse-checkout
  5. 이제 pull 로 원격 저장소에서 파일을 가져오면 sparse-checkout 에 기술한 경로의 파일만 가져온다.

    git pull origin master

Ref


Related content

git 서브모듈(submodule) 로 외부 프로젝트 사용하기
git 서브모듈(submodule) 로 외부 프로젝트 사용하기
More like this
SourceTree 기본 브랜치를 master 에서 main 으로 변경하기
SourceTree 기본 브랜치를 master 에서 main 으로 변경하기
More like this
gitlab 프로젝트 리셋하기
gitlab 프로젝트 리셋하기
More like this
apache httpd에서 버전관리 메타 데이타 디렉터리(.svn, .git) 접근 방지
apache httpd에서 버전관리 메타 데이타 디렉터리(.svn, .git) 접근 방지
More like this
git 버전 관리 무시 목록(ignore) 설정법(.gitignore)
git 버전 관리 무시 목록(ignore) 설정법(.gitignore)
More like this
도커로 깃랩 설치하기(install gitlab using docker)
도커로 깃랩 설치하기(install gitlab using docker)
More like this