Github에서 sub directory 또는 file 1개만 가져오는 방법

간혹 github을 clone 하려고 할 때, sub directory만 필요한데 생각보다 clone이 가능한 github repository 코드 전체 용량이 심하게 클 경우 clone을 하는게 망설여질 때가 있습니다.

이럴 때 적용할 수 있는 간단한 방법이 있습니다

먼저 해당 sub directory 또는 file을 저장할 local directory를 생성후 해당 directory로 이동합니다

mkdir project
cd project

그러고 나서 아래 github 관련된 명령어를 순차적으로 실행시켜 주시면 됩니다

git init

git config core.sparseCheckout true

git remote add -f origin <clone 가능한 git url>

echo "<갖고 오고 싶은 directory 주소/*>" .git/info/sparse-checkout

git pull origin master

아래 예시를 통해서 좀 더 자세히 보여드리겠습니다

git init

git config core.sparseCheckout true

git remote add -f origin https://github.com/udacity/DSND_Term2.git

echo "lessons/ObjectOrientedProgramming/*"> .git/info/sparse-checkout

git pull origin master

여기서 echo 다음에 가지고올 directory 주소/* 를 하면 sub dir 하위의 파일들을 전부 가지고 옵니다. 만약에 파일 1개만 가지고 오고 싶으시다면 그 파일의 path만 echo 다음에 적어주시면 됩니다.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s