Git Flow share

today 2016-05-04 face Posted by appkr turned_in Work & Play forum 0

Git Flow 는 Vincent Driessen이 제안한 깃 브랜칭 전략을 실행할 수 있도록 돕는 Git 확장 프로그램이다. 이 전략은 masterdevelop을 각각 배포 및 개발 브랜치로 사용하면서, feature, release, hotfix 등을 위한 임시 브랜치를 사용한다.

아래 그림은 Git을 소개하는 웹 문서나 서적에서 한번은 본 그림일 것이다. 많은 개발자들이 이 전략을 모범 사례로 인식하고, 따르고 있다는 방증이다.

이 포스트는 Git Flow의 기본적인 사용법을 담고 있다. 사실 여기 수록한 내용이 전부인 듯 하다.

• • •

1. 설치

홈브루로 설치한다. 맥포트, wget/curl로 설치한다면 이 위키 문서를 참고한다.

$ brew install git-flow

$ git flow version
# 0.4.1

$ git flow
# usage: git flow <subcommand>
# 
# Available subcommands are:
#    init      Initialize a new git repo with support for the branching model.
#    feature   Manage your feature branches.
#    release   Manage your release branches.
#    hotfix    Manage your hotfix branches.
#    support   Manage your support branches.
#    version   Shows version information.
# 
# Try 'git flow <subcommand> help' for details.

feature, release, hotfix, support 등의 하위 명령이 있다.

2. 데모 프로젝트

데모 프로젝트를 만들고, Git 및 Git Flow를 초기화한다.

$ git init gitflow-demo && cd gitflow-demo

~/gitflow-demo(branch:master) $ 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/]
# Release branches? [release/]
# Hotfix branches? [hotfix/]
# Support branches? [support/]
# Version tag prefix? []

Git Flow 초기화 과정에서 masterdevelop 브랜치를 자동으로 만들어 준다. 그리고, feature, release, hotfix로 사용할 브랜치의 접두어 정보를 미리 설정한다. 초기화 과정을 마치면, 자동으로 develop 브랜치로 체크아웃된다.

~/gitflow-demo(branch:develop) $ git branch
# * develop
#   master

3. Feature 개발

모든 작업은 develop 브랜치에서 시작한다. feature start 이름으로 시작하고, feature finish 이름으로 끝난다. 다른 하위 명령도 모두 마찬가지다.

~/gitflow-demo(branch:develop) $ git flow feature start awesome
# Switched to a new branch 'feature/awesome'
# 
# Summary of actions:
# - A new branch 'feature/awesome' was created, based on 'develop'
# - You are now on branch 'feature/awesome'
# 
# Now, start committing on your feature. When done, use:
# 
#      git flow feature finish awesome

자세히 보면, develop 브랜치에서 feature/awesome 브랜치를 땄고, 새로 만든 브랜치로 이동했다. 이제 Feature를 개발하고, 평상시 처럼 커밋하면 된다.

~/gitflow-demo(branch:feature/awesome) $ git commit -am '...'
~/gitflow-demo(branch:feature/awesome) $ git commit -am 'feature finished'

계획했던 개발이 끝나면, Git Flow로 Feature 개발을 끝낸다.

~/gitflow-demo(branch:feature/awesome) $ git flow feature finish awesome
# Summary of actions:
# - The feature branch 'feature/awesome' was merged into 'develop'
# - Feature branch 'feature/awesome' has been removed
# - You are now on branch 'develop'

Git Flow가 자동으로 feature/awesome 브랜치를 develop 브랜치에 머지하고, 필요 없는 브랜치는 삭제했다.

4. 릴리스

릴리스도 develop 브랜치에서 시작한다. 최종 결과는 master 브랜치에 적용된다.

~/gitflow-demo(branch:develop) $ git flow release start 0.0.1
# Switched to a new branch 'release/0.0.1'
# 
# Summary of actions:
# - A new branch 'release/0.0.1' was created, based on 'develop'
# - You are now on branch 'release/0.0.1'
# 
# Follow-up actions:
# - Bump the version number now!
# - Start committing last-minute fixes in preparing your release
# - When done, run:
# 
#      git flow release finish '0.0.1'

Git Flow가 develop 브랜치에서 release/0.0.1 브랜치를 땄다. 이제 코드에 수정할 부분들을 수정하면 된다. 버전 번호가 하드코드도 되어 있다면 수정하고, README.md 등에 설치/사용법들을 업데이트하는 작업이 될 것이다.

~/gitflow-demo(branch:release/0.0.1) $ git commit -am '...'
~/gitflow-demo(branch:release/0.0.1) $ git commit -am 'release ready'

이제 Git Flow로 릴리스 작업을 끝낸다.

~/gitflow-demo(branch:release/0.0.1) $ git flow release finish 0.0.1

에디터가 총 세 번 뜬다.

  1. 릴리스를 master 브랜치에 머지할 때 메시지를 입력하는 에디터
  2. 릴리스의 태그를 메기는 에디터
  3. 릴리스 브랜치에서 변경된 내용을 포함해서 develop 브랜치에 머지할 때 메시지를 입력하는 에디터

최종 메시지는 다음과 같다. origin의 변경사항도 가져온다는 점을 눈여겨봐야 한다.

# Summary of actions:
# - Latest objects have been fetched from 'origin'
# - Release branch has been merged into 'master'
# - The release was tagged 'v0.0.1'
# - Release branch has been back-merged into 'develop'
# - Release branch 'release/0.0.1' has been deleted

5. 핫 픽스

Feature 개발과 다를 바 없다. 다만, 핫 픽스는 릴리스에 바로 반영된다는 점이 다르다. 다시 말하면, Feature 개발과 릴리스를 합쳐 놓은 동작이다.

~/gitflow-demo(branch:develop) $ git flow hotfix start hotfix1
# Switched to a new branch 'hotfix/hotfix1'
# 
# Summary of actions:
# - A new branch 'hotfix/hotfix1' was created, based on 'master'
# - You are now on branch 'hotfix/hotfix1'
# 
# Follow-up actions:
# - Bump the version number now!
# - Start committing your hot fixes
# - When done, run:
# 
#      git flow hotfix finish 'hotfix1'
~/gitflow-demo(branch:hotfix/hotfix1) $ git commit -am '...'
~/gitflow-demo(branch:hotfix/hotfix1) $ git commit -am 'hotfix done'
~/gitflow-demo(branch:hotfix/hotfix1) $ git flow hotfix finish hotfix1

역시 에디터가 세 번 뜬다. 최종 메시지는 다음과 같다.

# Summary of actions:
# - Latest objects have been fetched from 'origin'
# - Hotfix branch has been merged into 'master'
# - The hotfix was tagged 'hotfix1'
# - Hotfix branch has been back-merged into 'develop'
# - Hotfix branch 'hotfix/hotfix1' has been deleted
~/gitflow-demo(branch:develop) $

모든 과정이 끝나면 자동으로 develop 브랜치로 돌아 온다.

6. 결론

엉뚱한 브랜치에 작업을 하고 머리를 쥐어 뜯은 적이 있다. Git Flow는 master 브랜치에서 직접 작업하는 것을 막고, develop 브랜치에서 모든 작업을 수행하도록 도와 준다. 수동으로 하려면 엄청 복잡하고, 실수하기 쉬운 작업 흐름을 Git Flow가 도와 준다. Git Flow를 이용하면 masterdevelop은 깔끔하게 하나의 라인으로 로그 그래프를 뽑을 수 있다. Git 만세다.

comments powered by Disqus
keyboard_arrow_up