프로젝트를 진행하다보면 JWT SecretKey나 AWS 관련 설정 파일과 같이 외부에 공개되기에 민감한 정보들이 있기 마련이다.
이러한 정보는 git이 제공하는 submodule을 통해 코드를 외부에 공개하면서도 안전하게 관리할 수 있다.
직접 실습을 진행하며 서브 모듈에 대해 이해해 나가보자!
git submodule add https://github.com/cmkxak/submodule-practice.git src/main/resources/security
위 과정을 마치면, 아래와 같이 .gitmodules 파일이 생성된다.
.gitmodules 파일에 적힌 내용은 아래와 같이 하위 레포지토리의 내용이 저장된 path와 하위 레포지토리의 url이 기본적으로 작성된다.
[submodule "src/main/resources/security"]
path = src/main/resources/security
url = https://github.com/cmkxak/gpt-config.git
이 후 .gitmodules 파일과 submodule에 저장된 내용들이 staging 되어 있는 상태가 되어있게 되는데 이를 commit 후 push 해주면 아래와 같이 서브모듈을 정상적으로 적용할 수 있다.
git submodule init
git submodule update
git clone --recurse-submodules <상위 레포지토리 경로>
-- 로컬에서 작업 중인 부분과 원격 저장소에 작업된 부분이 다른 경우 머지 까지 진행
git submodule update --remote --merge
-- .gitmodules 파일에 정의되어 있는 브랜치의 최신 버전으로 업데이트 (혹은 default 브랜치)
git submodule update --remote
https://hudi.blog/git-submodule/
https://tecoble.techcourse.co.kr/post/2021-07-31-git-submodule/