기타
[Git] 하위 디렉토리만 가져오기
마고커
2023. 10. 19. 13:45
Git을 사용하다보면 특정 디렉토리 안에 모든 프로젝트를 넣어두는 경우를 보게 된다.
대표적으로 Google Research도 그런데 https://github.com/google-research/google-research git 안에 수 많은 프로젝트가 한꺼번에 담겨 있다.
그 중 하나의 프로젝트만 가져오려면 아래와 같이 하면 된다.
~$ git clone --depth 1 --no-checkout INSERT_REPO_REMOTE_URL
//root folder of the same name is created
~$ cd INSERT_ROOT_FOLDER_NAME/
~$ git sparse-checkout set INSERT_DESIRED_SUBDIRECTORY_RELATIVE-PATH
/* the relative path is the path relative to the current -
- working directory, which should be the cloned root folder above */
~$ git checkout
https://medium.com/@judyess/how-to-clone-specific-subdirectory-branch-with-git-3fb02fd35b68 참조
이렇게 적혀 있으면 어려우니 예시를 들어, google-research 안의 tsmixer/tsmixer-basic 프로젝트를 가져온다면 아래와 같이 하면 된다.
~$ git clone --depth 1 --no-checkout https://github.com/google-research/google-research
~$ cd google-research/
~$ git sparse-checkout set tsmixer/tsmixer-basic
~$ git checkout
google-research 디렉토리 안에 tsmixer/tsmixer-basic 이 생기고, 그 안에 파일들을 가져왔음을 확인할 수 있다.