실무에서 하나의 Git 프로젝트를 여러 원격 저장소(Remote Repository) 와 동시에 관리해야 하는 상황은 생각보다 자주 발생한다.
예를 들면:
이 글에서는 Git multi remote 개념부터 실전 운영 방법까지 정리한다.
Git에서 remote 는 로컬 저장소와 연결된 원격 저장소의 별칭(alias) 이다.
기본적으로는 origin 하나만 존재한다.
git remote -v
origin https://github.com/user/project.git (fetch)
origin https://github.com/user/project.git (push)
하지만 Git은 remote 개수에 제한이 없다.
| 코드 미러링 | GitHub ↔ GitLab 동시 관리 |
| Fork 구조 | upstream(원본) + origin(내 fork) |
| 권한 분리 | 읽기 전용 remote / 쓰기 전용 remote |
| 배포 분리 | 개발용 저장소 / 배포 자동화용 저장소 |
git remote add <remote-name> <repository-url>
git remote add origin https://github.com/user/project.git
git remote add gitlab https://gitlab.com/user/project.git
확인:
git remote -v
origin https://github.com/user/project.git (fetch)
origin https://github.com/user/project.git (push)
gitlab https://gitlab.com/user/project.git (fetch)
gitlab https://gitlab.com/user/project.git (push)
| 용도 | Remote 이름 |
| 기본 저장소 | origin |
| 원본 오픈소스 | upstream |
| GitLab | gitlab |
| 백업 | backup |
| 배포용 | deploy |
❗ origin은 내가 push하는 기준 저장소 로 유지하는 것을 추천
git push origin main
git push gitlab main
git pull origin main
git pull upstream main
origin → 내 fork
upstream → 원본 저장소
git remote add upstream https://github.com/original/project.git
확인:
git remote -v
upstream 최신 코드 가져오기
git rebase upstream/main
git checkout main
git merge upstream/main
또는 rebase:
git rebase upstream/main
git push origin main
git push gitlab main
git remote set-url --add --push origin https://github.com/user/project.git
git remote set-url --add --push origin https://gitlab.com/user/project.git
확인:
git remote -v
이제 한 번만 실행해도:
git push origin main
→ 두 저장소에 동시에 push
⚠️ 실무에서는 실수 방지를 위해 CI/CD 미러링 방식을 더 선호하는 경우도 많음
git remote set-url origin https://new-url.git
git remote remove gitlab
git remote set-url --push upstream DISABLE
origin → 개인 GitHub (주 저장소)
gitlab → 회사 GitLab (미러)
upstream → 오픈소스 원본
origin → 개발 저장소
deploy → ArgoCD / CI 배포 전용
Git의 multi remote 기능은:
핵심은 개수보다 “역할 분리”와 “명확한 규칙”이다.
| jekyll로 github.io 블로그 만들기 - 7 (fix: build error 수정) (0) | 2024.09.16 |
|---|---|
| jekyll로 github.io 블로그 만들기 - 6 (0) | 2024.09.15 |
| jekyll로 github.io 블로그 만들기 - 5 (0) | 2024.09.14 |
| jekyll로 github.io 블로그 만들기 - 4 (5) | 2024.09.13 |
| jekyll로 github.io 블로그 만들기 - 3 (4) | 2024.09.12 |