github

[Git] Submodule 사용하기

JM Lee 2024. 4. 17. 21:39
728x90
서브모듈 명령 코드

 

1. 서브모듈 시작하기

# 메인모듈 로컬 상에 받아오기
> git clone <main repository address>
# 서브모듈 생성 코드
> git submodule add <sub repository address>
# 서브모듈 생성한 것을 커밋하여 확정짓기
> git add .
> git commit -m "feat: add submodules"

 

2. 서브모듈 포함된 깃 클론하기

# 메인모듈 클론
> git clone git@github.com:user/main-repo.git
# 서브모듈 초기화 : 지정된 path에 모듈 등록
> git submodule init
# 서브모듈 업데이트
> git submodule update


# 위 3단계 한 번에 하고 싶다면?
> git clone --recurse-submodules git@github.com:user/main-repo.git

 

3. 서브모듈 상태 확인

> git submodule status
#  07b6383bae047572b5c4c7b8e41b5cdd7935c9c8 sub (heads/main)
# : heads = main, 최신 커밋ID가 나타남

 

4. 서브모듈 업데이트

# 새 커밋
> git add .
> git commit -m "new commit"
# 서브모듈 업데이트
> git submodule update —remote
# +7e39f89295c7886ce1c60aa67a205063fe52e146 sub (remotes/origin/HEAD)
# : 달라진 커밋 ID 확인