728x90
1. 상황 예시
- 내 저장소 : https://gitlab.example.com/mygroup/myrepo.git
- 다른 저장소 : https://gitlab.com/othergroup/otherrepo.git
- 목표 :
- 다른 저장소의 feature/old-work 브랜치를 가져옴
- 내 저장소에 **migrate/old-work**라는 새 브랜치로 푸시
2. 작업 흐름 그림
[다른 저장소]
feature/old-work
│ fetch
▼
[로컬 저장소]
migrate/old-work
│ push
▼
[내 저장소]
migrate/old-work
3. 명령어 실행 과정
1) 내 저장소 클론
git clone https://gitlab.example.com/mygroup/myrepo.git
cd myrepo
📷 예시 결과
Cloning into 'myrepo'...
remote: Enumerating objects: 120, done.
remote: Counting objects: 100% (120/120), done.
remote: Compressing objects: 100% (80/80), done.
Receiving objects: 100% (120/120), 45.67 KiB | 2.3 MiB/s, done.
2) 다른 저장소 원격 등록
git remote add legacy https://gitlab.com/othergroup/otherrepo.git
📷 예시 결과
# 원격 저장소 목록 확인
git remote -v
origin https://gitlab.example.com/mygroup/myrepo.git (fetch)
origin https://gitlab.example.com/mygroup/myrepo.git (push)
legacy https://gitlab.com/othergroup/otherrepo.git (fetch)
legacy https://gitlab.com/othergroup/otherrepo.git (push)
3) 다른 저장소의 브랜치 가져오기
git fetch legacy feature/old-work
📷 예시 결과
From https://gitlab.com/othergroup/otherrepo
* branch feature/old-work -> FETCH_HEAD
* [new branch] feature/old-work -> legacy/feature/old-work
4) 로컬 새 브랜치 생성
git checkout -b migrate/old-work legacy/feature/old-work
📷 예시 결과
Branch 'migrate/old-work' set up to track remote branch 'feature/old-work' from 'legacy'.
Switched to a new branch 'migrate/old-work'
5) 내 저장소에 푸시
git push -u origin migrate/old-work
📷 예시 결과
Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (30/30), done.
Writing objects: 100% (42/42), 5.12 KiB | 5.12 MiB/s, done.
remote:
remote: Create merge request for migrate/old-work:
remote: https://gitlab.example.com/mygroup/myrepo/-/merge_requests/new?merge_request%5Bsource_branch%5D=migrate%2Fold-work
4. 정리
- git fetch → 브랜치 이력만 로컬로 가져옴 (충돌 없음)
- git checkout -b 새브랜치 legacy/브랜치 → 가져온 브랜치를 기반으로 새 로컬 브랜치 생성
- git push -u → 내 저장소에 새 브랜치 생성 + 추적 설정
💡 팁
- 브랜치 이름은 프로젝트 상황에 맞게 변경 가능
- 원격 이름(legacy)도 원하는 대로 지정 가능
- 필요하면 여러 브랜치를 순서대로 가져와서 올릴 수 있음
요약
# 1) 내 저장소 클론
git clone https://gitlab.dexta.kr/<group>/<repo>.git
cd <repo>
# 2) 다른 저장소 원격 추가
git remote add legacy https://gitlab.com/dextadev/<repo>.git
# 3) 다른 저장소 브랜치 가져오기
git fetch legacy feature/old-work
# 4) 로컬 새 브랜치 생성 (가져온 브랜치 기반)
git checkout -b migrate/old-work legacy/feature/old-work
# 5) 새 브랜치를 내 저장소에 푸시
git push -u origin migrate/old-work
728x90
'공부 > 추가공부' 카테고리의 다른 글
| 브라우저 저장소 (쿠키, 웹스토리지, 로컬스토리지, 세션스토리지) (0) | 2025.12.02 |
|---|---|
| PoC(개념 증명, Proof of Concept) (0) | 2025.11.05 |
| 프로젝트 관리(gantt) (0) | 2025.06.30 |
| offset (0) | 2025.06.23 |
| 실행 중인 Docker 컨테이너에서 KST로 시간대 변경 (0) | 2025.05.22 |