-
Git Repository copyInfra/Git 2024. 12. 8. 14:56
monorepo로 구성되어 있던 특정 package를 분리하기 위해 repositroy의 형상을 다른 repositroy로 이관하는 작업을 하게 되었습니다. 기존 repositroy의 commit 이력과 브랜치들도 다 같이 옮겨가는 니즈가 있어 해당 작업 내용을 남기게 되었습니다.
Git clone mirror option
기존 repositroy의 commit 이력과 브랜치들도 복사하기 위해 git clone mirror option을 사용합니다.
Git clone mirror vs bare
git clone에는 mirror와 bare option이 있습니다. mirror option은 기본적으로 bare option을 포함하고 있으며 bare option 과는 달리 기존 repositroy의 local branch들이 clone 되는 대상의 local branch 들에 맵핑되며 모든 refs를 맵핑합니다.
적용
git clone mirror option을 사용하여 기존 repositroy를 clone 합니다.
git clone --mirror <기존 git repository 주소> # 특정 branch clone git clone -b <branch 이름> --single-branch --mirror <기존 git repository 주소>
clone 한 디렉토리에서 아래의 명령어를 통해 새로운 repositroy에 연결하고 push 합니다.
git remote set-url origin <새로운 git repository 주소> git push --mirror
마무리
평소에 git client를 사용하여 git command에 대한 내용을 간과하고 있었습니다. 간단한 내용이지만 repositroy 형상관리를 위해 알아두고 사용하면 좋겠습니다.
참고 자료
https://velog.io/@hoo00nn/Git-Repository-%EB%B3%B5%EC%82%AC%ED%95%98%EA%B8%B0
https://pinocc.tistory.com/138
'Infra > Git' 카테고리의 다른 글
Monorepo에서 다른 패키지를 참조하여 빌드할 때 GitHub Actions 작성 방법 (0) 2025.03.30 GitHub Actions Auto tagging (0) 2024.11.17 GitHub 2FA(2단계 인증) 설정 (0) 2024.07.28 Github PR Reviewer 자동 추가하기 (1) 2024.01.27