git submodule
git
쓰는 꼴
git submodule update --init --recursive다른 저장소를 커밋 하나에 고정해 내 저장소 안에 둡니다 — 그냥 클론하면 폴더가 비어 있어 update --init이 필요하고, 부모가 붙드는 것은 브랜치가 아니라 커밋입니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| add <url> <path> | pin another repository at a path |
| update --init | fill in a submodule folder that a clone left empty |
| --recursive | go into submodules of submodules |
| update --remote | move the pin to the tip of the tracked branch |
| status | the commit each submodule sits at |
| deinit <path> | unregister it |
| foreach <cmd> | run a command in each one |
예시
git submodule update --init --recursivethe command that fills empty submodule folders after a clone
git submodule add https://github.com/x/lib.git vendor/libadds a dependency as a submodule
git submodule update --remoteupdates the pinned commit to the branch tip
되돌리는 방법이 여럿이라 헷갈립니다 — 가리키는 곳을 옮기는 것과 새 커밋을 얹는 것은 다릅니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. git submodule은 무엇을 하나요?
다른 저장소를 커밋 하나에 고정해 내 저장소 안에 둡니다 — 그냥 클론하면 폴더가 비어 있어 update --init이 필요하고, 부모가 붙드는 것은 브랜치가 아니라 커밋입니다.
Q. 어떻게 치나요?
git submodule update --init --recursive — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 7개입니다. 전체 목록은 man git에 있습니다. 이 명령은 git 갈래입니다.
같이 보는 명령
man 페이지: man git-submodule