프로그래밍

[Git] 두 개의 저장소 합치기(merge two git repositories)

채윤아빠 2022. 5. 26. 15:28
728x90
반응형

깃(Git)의 두 개의 저장소(Repository)를 합치는 방법은 다음과 같습니다.


$ git clone https://gitlab.myhost.net/remain_project.git # 합친 후, 남겨질 프로젝트 저장소 복사
# cd remain_project/ # 저장소 폴더로 이동

$ git config --local user.email "hanwhhanwh@gmail.com" # 저장소의 사용자 이메일 주소 등록
$ git config --local user.name "Wonhee Han" # 저장소의 사용자 이름 등록

$ git remote add added_project https://gitlab.myhost.net/added_project.git # 합칠 저장소
$ git fetch added_project --tags # 모든 태그 및 브랜치를 가져옵니다.
From https://gitlab.myhost.net/added_project
 * [new branch]      16984      -> added_project/16984
 * [new branch]      17011      -> added_project/17011
 * [new branch]      17033      -> added_project/17033
 * [new branch]      17037      -> added_project/17037
 * [new branch]      b0.6.5     -> added_project/b0.6.5
 * [new branch]      b0.7.0     -> added_project/b0.7.0
 * [new branch]      b0.7.1     -> added_project/b0.7.1
 * [new branch]      b0.7.2     -> added_project/b0.7.2
 * [new branch]      b0.7.3     -> added_project/b0.7.3
 * [new branch]      b0.7.4     -> added_project/b0.7.4
 * [new branch]      master     -> added_project/master
 * [new branch]      v0.8       -> added_project/v0.8

$ git merge --allow-unrelated-histories added_project/v0.8 # or whichever branch you want to merge
Merge made by the 'recursive' strategy.
 scripts/tgz_logs-vpc_gabo.sh |  12 ++
 src/constants.py             |   8 +-
 src/m_main.py                |  22 +++-
 src/static/logs.html         | 264 +++++++++++++++++++++++++++++++++++++++++++
 src/templates/control.html   |  75 ++++++------
 5 files changed, 341 insertions(+), 40 deletions(-)
 create mode 100755 scripts/tgz_logs-vpc_gabo.sh
 create mode 100644 src/static/logs.html

$ git remote remove added_project # 저장소 삭제
$ git push
warning: redirecting to https://gitlab.myhost.net/remain_project.git/
Enumerating objects: 51, done.
Counting objects: 100% (44/44), done.
Delta compression using up to 4 threads
Compressing objects: 100% (15/15), done.
Writing objects: 100% (35/35), 6.36 KiB | 1.59 MiB/s, done.
Total 35 (delta 22), reused 29 (delta 17), pack-reused 0
To https://gitlab.myhost.net/remain_project
   eb2d3aa..81030bb  master -> master

위 과정으로 두 개의 저장소가 합쳐집니다.


참고자료