xtring.dev

[Git] GitLab에서 GitHub로 commit log를 유지하여 Clone하기 본문

for Dev./Git | Github

[Git] GitLab에서 GitHub로 commit log를 유지하여 Clone하기

xtring 2020. 7. 15. 09:55
반응형

 

 

 

회사에서 관리하는 Remote Repository는 이전에 GitLab에서 관리되어지고 있다가 서버 개발자 분께서 자동 배포기능을 만들기 위해 GitHub로 프로젝트를 이관하면 어떻겠냐는 제한을 했습니다. 그런데 이전 commit log를 모두 날려버린다면 너무 아깝기도 하고 작성했던 코드도 모두 날리게 되어 쉽게 실행하지 못하던 와중에 좋은 방법을 찾게 되었습니다.

 

 

Repository 미러링

 

1. open terminal

 

2. 복사하고자 하는 저장소(GitLab)의 bare clone을 생성

git clone --bare https://gitlab.com/user_id/old-repo.git

 

3. 새로운 저장소(GitHub)를 만들고 mirror-push를 진행합니다.

cd old-repo.git
git push --mirror https://github.com/user_id/new-repo.git

 

4. 클론된 저장소를 제거(선택)

 

 

 

* 설명에 따르면 대부분의 경우 위의 방법으로 mirror-clone이 가능하지만, GitHub 정책상 크기가 100MB를 넘어가는 파일이 한번이라도 commit 되었던 적이 있을 경우 오류가 발생하여 push가 불가능하게 됩니다.

 

 

 

 

 

 

100MB가 넘는 크기의 파일을 지닌 저장소 미러링하기

 

1. Git lfs와 BFG Repo Cleaner를 설치

 

2. 복사하고자 하는 저장소(GitLab)의 clone을 생성

git clone --mirror https://gitlab.com/user_id/old-repo.git

 

3. 커밋 히스토리 내에서 Large file를 찾아 tracking

git filter-branch --tree-filter 'git lfs track "*.{zip,jar}"' -- --all

 

4. BFG를 이용하여 해당 파일들을 Git lfs로 변경

java -jar ~/usr/bfg-repo-cleaner/bfg-1.13.0.jar --convert-to-git-lfs '*.zip'
java -jar ~/usr/bfg-repo-cleaner/bfg-1.13.0.jar --convert-to-git-lfs '*.jar'

 

5. 새로운 저장소(GitHub)로 mirror-push를 진행

cd old-repository.git
git push --mirror https://github.com/user_id/new-repo.git

 

6. 클론된 저장소 제거(선택)

 

 

 

 

 

 

 

* 출처
GitHub Help
StackOverflow - How to import git repositories with files?
lazyren github.io

반응형
Comments