포스트

0] 깃 레포지토리에서 새로운 서브 모듈로 분리하기

  • GitHub, GitLab, Bitbucket 등에서 새로운 Git 레포를 생성합니다.
  • 예시: https://github.com/username/submodule-repo.git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 1. 하위 폴더를 Git 인덱스에서 제거 (존재하지 않는다면 무시)
git rm -r --cached 하위폴더명

# 2. 하위 폴더를 새로운 Git 레포로 변환
cd 하위폴더명
git init
git remote add origin https://github.com/username/submodule-repo.git
git add .
git commit -m "Initialize prostore repo"
git checkout -b main
git push -u origin main



3️⃣** 상위 레포의 로컬에서 기존 폴더를 삭제하고, 서브모듈의 원격저장소로부터 불러와서 대체**

1
2
3
4
5
6
7
# 3. 상위 레포로 돌아가서 기존 하위폴더 삭제하고 대신에 서브모듈 추가
cd ..
rm -rf 하위폴더명  # 기존 폴더 삭제. powershell일 경우 다른 명령어. 즉, Remove-Item -Recurse -Force 하위폴더명 
git submodule add https://github.com/username/submodule-repo.git 하위폴더명
git commit -m "Convert 하위폴더명 to a submodule"
git push

4️⃣ 서브 모듈 업데이트(필수)

1
2
# 4. 상위폴더에서 서브모듈 업데이트 명령 (필수)
git submodule update --init --recursive


sticker

저의 경우에는 다음과 같이 기존 **prostore**라는 평범한 하위폴더였던 것이 **prostore @ 64353ae **로 변했습니다. 그리고 클릭하게 되면 **prostore** 하위 레포지토리로 이동하게 되네요:)

서브모듈 관계


이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.