Post

[DevOps]GitFlow

Git을 다루고는 있지만 Git branch를 어떻게 운용해야하는 지에 대한 내용은 잘 모르던 찰나 아래와 같은 git branch 전략을 소개하는 영상을 보고 흥미를 가지게 되어 정리하게 되었습니다.

Ⅰ. Git Branch strategy

Git Branch 전략은 팀이 협업하고 소스 코드를 관리하는 방법을 정의하는 것으로 영상에서는 GitFlow, Github Flow, Trunk-based, Gitlab Flow 등의 branch 전략들이 존재한다고 소개하였습니다.

그 중 대표적은 GitFlow와 Trunk-based에 대해 작성해보겠습니다.

Ⅱ. GitFlow

그중 Vincent Driessen가 만든 GitFlow라는 전략으로 간단하게 말해서 각각 메인, 개발, 기능, 출시 준비, 버그 수정의 5가지 큰 flow가 존재한다고 합니다.

1 Figure 1 : Overview of GitFlow

  1. main : 메인 브랜치로 배포하는
  2. develop : 메인 브랜치의 복사본으로 개발에 사용
  3. feature : 개발 브랜치에서 바로 수정은 위험하기에 기능을 따로 생성
  4. release : 출시 버전을 준비하는 브랜치
  5. hotfix : 배포 이후 긴급한 수정을 하는 브랜치

위와 같이 5가지의 브랜치를 사용하는 전략으로 관련한 git flow 명령어를 다음과 같이 알아보도록 하겠습니다.

ⅰ. git-flow

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# git-flow Ubuntu 환경에서 설치
root@db6507abb13e:/app# apt-get install git-flow

# 초기화.
root@db6507abb13e:/app# git flow init
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master] 
Branch name for "next release" development: [develop] 

How to name your supporting branch prefixes?
Feature branches? [feature/] 
Bugfix branches? [bugfix/] 
Release branches? [release/] 
Hotfix branches? [hotfix/] 
Support branches? [support/] 
Version tag prefix? [] 
Hooks and filters directory? [/app/.git/hooks] 

# develop 브랜치 생성 확인
root@db6507abb13e:/app# git branch
* develop
  master

# git-flow 없이는 그냥 아래와 같이 생성하고 merge하면 됩니다.
git branch develop
git push -u origin develop

ⅱ. Supporting branches

이렇게 생성된 develop 브랜치를 보조하는 Supporting branches들은 아래와 같은형태로 수정해나아가면 됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
root@db6507abb13e:/app# git flow feature start feature_branch
Switched to a new branch 'feature/feature_branch'

Summary of actions:
- A new branch 'feature/feature_branch' was created, based on 'develop'
- You are now on branch 'feature/feature_branch'

Now, start committing on your feature. When done, use:

     git flow feature finish feature_branch

root@db6507abb13e:/app# git flow feature finish feature_branch

Switched to branch 'develop'
Already up to date.
Deleted branch feature/feature_branch (was 1cfe78f).

Summary of actions:
- The feature branch 'feature/feature_branch' was merged into 'develop'
- Feature branch 'feature/feature_branch' has been locally deleted
- You are now on branch 'develop'


git checkout develop # develop 브랜치로 이동
git checkout -b feature_branch # 새로운 feature_branch를 생성하고 이동

git checkout develop # develop 브랜치로 이동
git merge feature_branch # feature_branch를 develop에 merge

Ⅲ. Trunk-based

해당 전략은 메인(또는 Trunk) 브랜치 하나만 잘 관리하자라는 마인드의 전략으로 개발 브랜치와 서포팅 브랜치 등을 만들지 않는 형태입니다. 즉, Main 또는 Trunk 브랜치에서 짧은 주기의 브랜치를 만들어 기능을 구현해 바로 병합하는 형식입니다.

이러한 형태는 Github flow도 비슷하다고 합니다. 이러한 형태의 방법은 소스코드가 한 곳에만 있어 관리가 용이하지만 테스트를 많이하고 자주 해야한다는 단점이 존재한다고 합니다.

1
2
git branch short_term # 짧은 주기의 브랜치 생성
git merge short_term # 기능 개발이 끝나면 바로 병합

Ⅳ. REFERENCES

  1. [Gitflow] 깃플로우 브랜치 전략
  2. A successful Git branching model By Vincent Driessen
  3. Git Flow에서 트렁크 기반 개발으로 나아가기



This post is licensed under CC BY 4.0 by the author.