NestJS를 공부하면서, 각각 다른 레포지토리에 만들었던 프로젝트들을 하나의 레포지토리에 폴더로 나눠서 정리해놓고 싶었다.
nest-social-login
이라는 하위 폴더로 옮기고 싶다.$ git remote add <child의 remote 이름> <child 레포지토리 주소>
$ git remote -v
를 통해 remote 확인이 가능하다.$ git subtree add --prefix=<parent 레포지토리에 저장할 폴더명> <child의 remote 이름> <parent 레포지토리 branch name>
$ git push
$ git submodule add <child 레포지토리 주소> <parent 레포지토리에 저장할 폴더명(생략하면 child 레토지토리 이름으로 자동 설정)>
[submodule "nest-social-login"]
path = nest-social-login
url = https://github.com/hocaron/Social-Login.git
서브모듈 프로젝트를 최신으로 업데이트하려면 서브모듈 디렉토리에서 git fetch
명령을 실행하고 git merge
명령으로 Upstream 브랜치를 Merge해야 한다.
메인 프로젝트로 돌아와서 git diff --submodule
명령을 실행하면 업데이트된 서브모듈과 각 서브모듈에 추가된 커밋을 볼 수 있다. 매번 --submodule 옵션을 쓰고 싶지 않다면 diff.submodule 의 값을 log
로 설정하면 된다.
후에 최근 작업으로 업데이트가 필요하다면 git submodule update --remote --merge
후에 푸시하면 된다.