[git] submodule로 프로젝트 합치기

제이브로·2024년 2월 7일
0

git

목록 보기
8/11
post-thumbnail

1. Submodule

Submodulegit저장소 안에 다른 git 저장소를 분리해서 넣는 것이다.

  • A 프로젝트에서 쓰던 코드를 B 프로젝트에서도 사용해야 할 경우에 사용
  • 저장소라 하위에 .git 파일이 있음을 알 수 있다.

2. Submodule 추가하기

$ git submodule add [서브모듈 url]

$ git submodule add https:github.com/username/subrepo.git

3. gitmodules파일

서브모듈이 추가되면, 서브모듈 이외에 .gitmodules라는 파일도 새롭게 생성되었다.

  • .gitmodules 파일은 서브 저장소와 하위 프로젝트 url의 매핑 정보를 담는다.

4. git clone --recursive 옵션

모든 submoduleclone해주는 옵션이다.

  • $ git clone --recursive {주소}
$ git clone --recursive https://github.com/username/repo.git

5. git submodule update --init --recursive

일반적으로 clone한 후 submodule을 업데이트하는 방법

  • main project에 연결되어 있는 subrepo의 정보를 가져와서 업데이트 한다.
$ git submodule update --init --recursive

5.1 특정 submodule 업데이트

특정 submodule을 지정해서 업데이트 할 수도 있다.

  • 모든 submodule을 다 가져와서 업데이트할 필요가 없기 때문이다.
$ git submodule update --init --recursive ./newsubrepo

6. git submodule update --remote --merge

--remoteremote repo의 최신 정보를 가져와서 update하는 것이다.

  • remote repo에 새로운 commit이 있는 경우 local main project에 새로운 sub project link가 연결되기 때문에 main projectupdate 된다. 따라서 main project에 변화가 생길 수 있으며, main project를 새로 commit 해야 한다
$ git submodule update --remote {remote repo} --merge

7. References

  1. noel-embedded blog
  2. soomlog blog
profile
기록하지 않으면 기록되지 않는다.

0개의 댓글