이 문서는 소스코드가 Gerrit과 GitLab 두 서버에 저장되어야 할 때의 방법을 정리한다.
개요
목적
- 소스코드가 두 저장소 관리 서버에 동일하게 저장되어야 하는 요구사항 만족
환경
- 저장소 형식: git
- 본 문서는 Gerrit과 GitLab 두 가지 서버를 고려한다
Solution A
GitLab Enterprise는 remote push 기능을 제공하고 있다. 원격 저장소 주소를 설정하면 GitLab 에 push된 변경사항이 원격 저장소에 push 된다.
Solution B
GitLab Community 는 remote push 기능을 지원하지 않기 때문에 로컬 저장소에서 push할 때 두 개의 저장소 서버에 push하는 방법을 사용할 수 있다.
본 예에서는 GitLab 저장소를 주 저장소로 고려한다.
Step 1) 저장소 생성
- GitLab 과 Gerrit 저장소 생성
- 두 번째로 생성되는 저장소는 생성 옵션에서 Initial Commit을 해제한다
Step 2) 저장소 clone
- GitLab 저장소를 로컬 저장소를 clone
- 작업된 소스코 로컬 저장소에 commit
Step 3) Git configuration 구성
- 로컬 저장소 폴더의 .git/config 파일에 두 번째 저장소 주소 추가
- 두 가지 방법 가능:
A) git remote set-url --add --push origin git://gerrit-url/something.git
B) .git/config 파일 수정
[remote "all'] 과 같이 추가해 놓으면 git push all 로써 한 번의 명령으로 두 remote 에 push 가능
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [remote "origin"] url = http://gitlab.curvc.com:30000/terry.hwang/spring3example.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [remote "gerrit"] url = "http://username@gerrit.curvc.com:48081/a/gitlab-mirror.git" fetch = +refs/heads/*:refs/remotes/gerrit/* push = refs/heads/*:refs/for/* [remote "all"] url = http://gitlab.curvc.com:30000/terry.hwang/spring3example.git url = "http://username@gerrit.curvc.com:48081/a/gitlab-mirror.git"
Step 4) Push 수행 방법
# > git push; git push gerrit