영감을 (inspire) 주고픈 개발 블로그

git sparsecheckout 으로 github에서 spring-projects example 들 중 원하는 프로젝트만 가져오기 본문

개발/세팅

git sparsecheckout 으로 github에서 spring-projects example 들 중 원하는 프로젝트만 가져오기

inspire12 2023. 12. 20. 18:27

Spring 의 큰 장점 중 하나는 문서화를 굉장히 잘해놓았다는 것 입니다. 

자바 8버전 이후로는 javadoc 을 이용해 코드 내에서도 버전과 사용법 등 문서화가 잘 되어있어서 코딩중에서도 읽으면서 공부 할 수 있습니다.. 

 

공식 사이트인 spring.io의 문서도 굉장히 친절하게 잘되어있습니다. 

https://spring.io

 

Spring | Home

Cloud Your code, any cloud—we’ve got you covered. Connect and scale your services, whatever your platform.

spring.io

 

게다가 각 예제 프로젝트들도 github에 올려져 있습니다 

https://github.com/spring-projects?q=example&type=all&language=&sort=

 

Spring

Spring Projects. Spring has 83 repositories available. Follow their code on GitHub.

github.com

 

그러나 이 github 프로젝트들을 받아보면 크기가 굉장히 크고 복잡해 보입니다. 이는 여러 Spring 예제들을 하나의 github 에 모아놨기 때문입니다.  

 

예를 들어 JPA 를 공부하다가 JPA21라는 걸 새로 알아 이 변경점을 알고 싶어졌습니다. 그래서 spring-data-examples 내의 jpa > jpa21 의 spring 프로젝트를 clone을 하려고 해도 다른 프로젝트까지 다 받아지게 됩니다.

 

이런 경우를 위해서 git clone sparsecheckout 라는 기능이 있습니다

이 방법은 git 세팅을 하기 때문에 기존에 .git 파일이 있다면 덮어쓰게 된다. 때문에 sparse를 위한 폴더를 하나 만들기를 추천한다.

 

그럼 한번 jpa21 프로젝트만 따로 받아보도록 하겠습니다. 

일단 clone을 받을 위치를 정합니다. 저는 ~/Document/workspace/sparse-project 라는 위치에서 이런 류의 sparsecheckout 이 필요한 project 를 받아써보고 있습니다. 

 

mkdir ~/Documents/workspace/sparse-project
cd ~/Documents/workspace/sparse-project

git init 
git remote add origin https://github.com/spring-projects/spring-data-examples.git

git config core.sparseCheckout true
echo 'jpa/jpa21/*' >> .git/info/sparse-checkout
git pull origin main

rm -rf .git

 

clone에 사용한 git 은 필요가 없기에 삭제하고 세팅 진행하겠습니다.

 

결과 

 

 

이제 다른 github 프로젝트의 부분을 받아보겠습니다. 예시로 제가 블로그에 쓰는 글의 예제 코드를 저장한 github repository에서 프로젝트를 가져와보겠습니다. 

 

git init 
git remote add origin https://github.com/inspire12/inspire12-blog-code.git

git config core.sparsecheckout true
echo 'inspire12-loadtest/*' >> .git/info/sparse-checkout
git pull origin main

rm -rf .git

 

결과 

 

 

 

반응형