Git submodule 활용하기
Published in
3 min readDec 4, 2019
프로젝트 세팅
개별 repository 만들기
- project-name
- project-name-client
- project-name-server
루트 프로젝트 clone
git clone https://github.com/<GITHUB_ID>/project-name.git
submodule 등록
cd project-name
git submodule add -b master https://github.com/<GITHUB_ID>/project-name-client.git client
git submodule add -b master https://github.com/<GITHUB_ID>/project-name-server.git server
client, server
폴더와.gitmodules
파일이 생성 됨- 변경 된 내용을 commit, push
프로젝트를 받아서 사용 하기
submodule 초기 설정
- submodule 초기화 및 소스 업데이트
git submodule init && git submodule update
submodule 별 동일 명령 실행
- 사용하려는 브랜치로 변경하고 최신 소스로 업데이트
git submodule foreach git checkout <브랜치 이름>
git submodule foreach git pull origin <브랜치 이름>
- npm module 설치 하기
git submodule foreach npm install
Submodule 제거
# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule
# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule
# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule