Git | GitLab

Git 레포지터리 미러링

비번변경 2021. 6. 1. 19:00

Git을 통해 레포지터리 미러링 방법에 대해 적어둔다.

레포지터리 내 100M 이상 파일도 함께 옮기고 싶다면 git-lfs, BFG Repo-Cleaner도 함께 사용해야 한다.

 

방법

1. git-lfs 레포지터리 설치

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash

 

2. git-lfs 설치

sudo yum install git-lfs
git lfs install

 

3. BFG Repo-Cleaner 다운로드

wget https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar

# 사용 방법 : jar 실행
java -jar ~/bfg-1.14.0.jar --convert-to-git-lfs '*.zip'

 

4. 레포지터리 미러링

# 클론
git clone --mirror <https://gitlab.com/exampleuser/old-repository.git>

# 깃 경로로 이동
cd old-repository.git

# 큰 파일 트래킹
git filter-branch --tree-filter 'git lfs track "*.{zip,jar}"' -- --all
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'

# 미러링 저장소로 푸시
git push --mirror <https://github.com/exampleuser/new-repository.git>

 

+ 미러링 동기화

# 깃 경로로 이동
cd old-repository.git

# 저장소 업데이트
git remote update

# 미러링 저장소로 푸시
git push --mirror <https://github.com/exampleuser/new-repository.git>

 

git을 이용한 미러링은 일회성이기 때문에 동기화는 수동으로 해야 한다.

728x90