5. 분산 환경에서의 Git
📚Contents
Pro Git
1. 분산 환경에서의 워크 플로
2. 프로젝트에 기여기
3. 프로젝트에 관리하기
분산 환경에서의 워크플로
👨🏻💻 중앙집중식 워크플로
중앙 저장소를 하나 두고 Clone한 개발자 모두 Push 권한을 부여
공유 저장소
개발자
개발자
개발자
Pro Git
공유 저장소
통합 관리자
개발자
개발자
Pro Git
👨🏻💻 Integration-Manager 워크플로
Github나 GitLab 같은 Hub 사이트를 통해 주로 사용하는 방식이다.
공유 저장소
공유 저장소
1
2
3
4
최고 관리자
개발자
Pro Git
👨🏻💻 Dictator and Lieutenants 워크플로
수백 명의 개발자가 참여하는 큰 프로젝트를 운영할 때 이 방식을 사용한다.
blessed
repository
개발자
개발자
중간 관리자
중관 관리자
프로젝트에 기여하기
Pro Git
🙅♂️ 프로젝트에 기여하기 전에...
1. 몇명의 개발자가 참여할 것인가?
2. 워크 플로우는 어떻게 할 것인가?
3. 프로젝트의 권한은 어떻게 할 것인가?
👨👦👦 👨👧👧 프로젝트 기여하기
- 비공개 소규모 팀 (중앙 집중식 워크플로)
-
비공개 대규모 팀 (Intergration-manager 워크플로)
- 비공개 프로젝트
- 공개 프로젝트
Pro Git
👨👦👦 👨👧👧 프로젝트 기여하기
- 대규모 공개 프로젝트와 이메일 통한 관리
Pro Git
$ git checkout -b topicA
... work ...
$ git commit
... work ...
$ git commit
$ git format-patch -M origin/master
0001-add-limit-to-log-function.patch
0002-changed-log-output-to-30-from-25.patch
👨👦👦 👨👧👧 프로젝트 기여하기
- 대규모 공개 프로젝트와 이메일 통한 관리
Pro Git

👨👦👦 👨👧👧 format-patch
- 사내 프로젝트 코드를 집에서 수정하고 반영하려면?
Pro Git
// 패치파일 생성
$ git format-patch {commit_id}
// 패치파일 적용하기
$ git apply {file_name.patch}
프로젝트 관리하기
Git 도구 - 서브모듈
🙋♂️서브 모듈은 언제 써야할까요?
Pro Git

1. 디자이너의 결과물을 개발자에게 전달
2. 개발자는 변경된 파일을 붙여넣기
3. Commit & Push
4. 서비스 배포
🙋♂️서브 모듈은 언제 써야할까요?
Pro Git

1. 디자인과 개발에 적용된 버전 차이 발생
2. 프로젝트 진행중 수정이 빈번하다면
=> 개발자가 너무 수고스러움
=> 커밋이 지저분해짐
🙋♂️개발자와 디자이너 영역을 별개로 다루자
Pro Git

서비스 레포지토리
(service_repo)
디자이너 레포지토리
(design_repo)
1. 서브모듈 시작하기 - 서브 모듈 추가
Pro Git
$ cd /service_repo/.../resources
=> 서브모듈을 추가할 루트로 이동
$ git submodule add http://stash.daou.co.kr/svc_design
Cloning into 'svc_design'... remote: Counting objects: 11, done. remote: Compressing objects: 100% (10/10), done. remote: Total 11 (delta 0), reused 11 (delta 0) Unpacking objects: 100% (11/11), done. Checking connectivity... done.
1. 서브모듈 시작하기 - .gitmodules
Pro Git
$ git status
On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitmodules new file: .../resources/static
1. 서브모듈 시작하기 - .gitmodules
Pro Git
$ cat ./gitmodules [submodule "resources/static"] path = resources/static url = http://stash.daou.co.kr/svc_design
- 서브디렉토리와 하위 프로젝트 URL의 매핑정보
1. 서브모듈 시작하기
Pro Git
$ git diff --cached .../resources/static
diff --git a/DbConnector b/DbConnector new file mode 160000 index 0000000..c3f01dc --- /dev/null +++ b/DbConnector @@ -0,0 +1 @@ +Subproject commit c3f01dc8862123d317dd46284b05b6892c7b29bc => static 디렉토리는 서브모듈로 취급하기 때문에 추적하지 않는다. 대신 통쨰로 특별한 커밋으로 취급한다.
2. 서브모듈 포함한 프로젝트 Clone
Pro Git
$ git clone http://stash.daou.co.kr/service_repo
$ cd service_repo
$ git submodule init
=> .gitmodule에 있는 정보를 기반으로 로컬 환경설정 파일 셋팅
$ git submodule update
=> 서브모듈에 저장된 스냅샷으로 리모트의 커밋 정보를 가져오고 checkout
3. 부모에서 서브모듈 변경
Pro Git
$ cd service_repo // 부모 프로젝트
$ git --pretty=short -1
commit b90da54bc5f7b0ca12eb313e1a57581f35ddce38
$ cd service_repo/resources/static // 자식 프로젝트
$ git --pretty=short -1
commit 0d2bb5b91c235fa77fdd8859d9ecbd270fd576d2
=> 각 레포는 각각 origin을 가지고 있고 서로다른 커밋을 바라보고 있다.
3. 부모에서 서브모듈 변경
Pro Git
$ cd service_repo/resources/static // 자식 프로젝트
$ git commit --allow-empty -m "Add new commit" // 빈 커밋
commit 0d2bb5b91c235fa77fdd8859d9ecbd270fd576d2
$ git log --pretty=short -1 // 0d2bb5b 에서 af2a90a 로 변경
commit af2a90a19766d5ab5ed7d5f59e88403245f99ab1
3. 부모에서 서브모듈 변경
Pro Git
$ cd service_repo // 부모 프로젝트
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
...
modified: resources/static (new commits)
3. 부모에서 서브모듈 변경
Pro Git
$ git diff
diff --git a/submodule_test_child b/submodule_test_child index 0d2bb5b..af2a90a 160000 --- a/submodule_test_child +++ b/submodule_test_child @@ -1 +1 @@ -Subproject commit 0d2bb5b91c235fa77fdd8859d9ecbd270fd576d2 +Subproject commit af2a90a19766d5ab5ed7d5f59e88403245f99ab1
3. 부모에서 서브모듈 변경
Pro Git
$ git commit -am "Update submodule"
$ cd service_repo/resources/static // 자식 프로젝트
$ git push origin master
$ cd service_repo // 부모 프로젝트
$ git push origin master
3. 부모에서 서브모듈 변경
Pro Git
$ git commit -am "Update submodule"
$ git push origin master
----------------------------------------------------------------
다른 작업자
$ git pull origin master
$ git submodule update
error: no such remote ref f370c4954db667a9c8815028e5905e13c78c48c9
...
3. 부모에서 서브모듈 변경
Pro Git
$ git push --recurse-submodules=check
The following submodule paths contain changes that can
not be found on any remote:
resources/static
Please try
git push --recurse-submodules=on-demand
or cd to the path and use
git push
to push them to a remote.
$ git config push.recurseSubmodules check
3. 부모에서 서브모듈 변경
Pro Git
$ git push --recurse-submodules=on-demend
...
c75e92a..82d2ad3 master -> master // 자식 프로젝트
...
3d6d338..9a377d1 master -> master // 부모 프로젝트
$ git config push.recurseSubmodules on-demand
4. 서브모듈 업데이트
Pro Git
$ cd service_repo/.../resources/static
$ git pull origin master
=> 서브모듈에 변경이 있다면 최신화 한다.
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
...
modified: .gitmodules
modified: resources/static (new commits)
5. 서브모듈 팁
Pro Git
$ git submodule foreach 'git stash'
$ git submodule foreach 'git checkout -b featureA'
$ git diff; git submodule foreach 'git diff'
Pro Git: 분산환경에서의 Git
By Jaewoo KIM