2014.2.10.[ 제 83 호 ] GIT Flow 를활용한효과적인소스형상관리 Part 2 : GIT Flow 실습과활용예제 소프트웨어공학센터경영지원 TF 팀 C o n t e n t s Ⅰ. GIT Flow 소개 Ⅱ. Branch 전략 Ⅲ. 실제사용예제 Ⅳ. 결론
SW 공학트렌드 동향분석 Webzine Ⅲ. 실제사용예제 1. GIT Flow 사용준비 GIT Flow 를사용할수있도록 GIT 과 GIT Flow 설치를진행하고, 무료 GIT Repository 인 GIT Hub 에 GIT Flow 를테스트해볼수있는 GIT Repository 를생성한다. 1) GIT 설치 GIT 프로그램은운영체제에자동으로설치되어있지않다. < 그림 1> 의다음 URL 에접속해서운영체제별로설치한다. http://git-scm.com/downloads MAC OS X 개발자라면링크에접속해서 Mac 아이콘을선택하고 dmg 설치파일을설치하고 GIT 을설치한다. 그림 1_GIT 설치 URL 출처 : http://git-scm.com/downloads GIT 을설치했다고해서 GIT Flow 를바로사용할수는없다. 01 2014 February (No.83)
$ git flow git: 'flow' is not a git command. See 'git --help'. Did you mean one of these? reflog show GIT Flow 를설치해야한다. 2) GIT Flow 설치 GIT Flow 는 MAC OS X, Linux(Unix), Windows 까지지원한다. 본인의운영체제에맞게 GIT Flow를설치한다. 설치주소는 https://github.com/nvie/gitflow/wiki/installation 에있다. 만약 MAC OS X 를사용하는개발자라면, 상기 URL 에서 MAC OS X 링크를따라들어가던지. https://github.com/nvie/gitflow/wiki/mac-os-x 에바로접속하여설치할수있다. 현재나와있는링크의내용으로는 GIT Flow 를설치하려면 Homebrew 나 MacPorts, Wget, Curl로설치할수있다. 어느것이든상관없이설치가가능하므로, 개발자가편한방식으로설치한다. 만약 Curl을이용한다면, 아래와같이실행하면설치가된다. curl -L -O https://raw.github.com/nvie/gitflow/develop/contrib/gitflow-installer.sh sudo bash gitflow-installer.sh https 주소에연결된 github.com 의 bash shell script 를다운받아 sudo 권한으로실행시킨결과는다음과같다. GIT Flow 과관련된스크립트는 /usr/local/bin 디렉토리에설치되는것을확인할수있다. $ curl -L -O https://raw.github.com/nvie/gitflow/develop/contrib/gitflow-installer.sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0sudo bash gitflow-installer.sh 100 2145 100 2145 0 0 2057 0 0:00:01 0:00:01 --:--:-- 2058 $ sudo bash gitflow-installer.sh Password: ### gitflow no-make installer ### Installing git-flow to /usr/local/bin Cloning repo from GitHub to gitflow Cloning into 'gitflow'... 02
SW 공학트렌드 동향분석 Webzine remote: Reusing existing pack: 1407, done. remote: Total 1407 (delta 0), reused 0 (delta 0) Receiving objects: 100% (1407/1407), 623.29 KiB 231.00 KiB/s, done. Resolving deltas: 100% (689/689), done. Checking connectivity... done Updating submodules Submodule 'shflags' (git://github.com/nvie/shflags.git) registered for path 'shflags' Cloning into 'shflags'... remote: Reusing existing pack: 454, done. remote: Total 454 (delta 0), reused 0 (delta 0) Receiving objects: 100% (454/454), 130.79 KiB 68.00 KiB/s, done. Resolving deltas: 100% (338/338), done. Checking connectivity... done Submodule path 'shflags': checked out '2fb06af13de884e9680f14a00c82e52a67c867f1' install: gitflow/git-flow -> /usr/local/bin/git-flow install: gitflow/git-flow-init -> /usr/local/bin/git-flow-init install: gitflow/git-flow-feature -> /usr/local/bin/git-flow-feature install: gitflow/git-flow-hotfix -> /usr/local/bin/git-flow-hotfix install: gitflow/git-flow-release -> /usr/local/bin/git-flow-release install: gitflow/git-flow-support -> /usr/local/bin/git-flow-support install: gitflow/git-flow-version -> /usr/local/bin/git-flow-version install: gitflow/gitflow-common -> /usr/local/bin/gitflow-common install: gitflow/gitflow-shflags -> /usr/local/bin/gitflow-shflags GIT Flow 가정상적으로설치되었는지터미널에서확인한다. command not found 결과가아닌 Usage 에대한결과가나오면정상적인것이다. $ 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. 03 2014 February (No.83)
3) GIT Hub 가입및 GIT Repository 생성 GIT Flow 사용을위한 GIT Repository를생성해야한다. 유명한 GIT Repository 인 GIT Hub 를사용하면된다. http://github.com 가입 / 로그인후, http://github.com/new 에서 GIT Flow 를테스트할 github project 를생성한다. 그림과같이 git-flow-test 라는이름으로프로젝트를생성한다. 여기에서는 ksmark라는계정을만들고테스트를진행한다. https://github.com/ksmark/git-flow-test 으로생성된것을볼수있다. 4) GIT Repository 생성 $ git remote add origin https://github.com/ksmark/git-flow-test.git $ mkdir git-flow-test $ cd git-flow-test/ $ touch README.md $ git init Initialized empty Git repository in /development/git-flow-test/.git/ $ git add. $ git commit -m 'first commit' [master (root-commit) fefd8fb] first commit 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README.md $ git push -u origin master Counting objects: 3, done. Writing objects: 100% (3/3), 217 bytes 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@github.com:ksmark/git-flow-test.git * [new branch] master -> master Branch master set up to track remote branch master from origin. https://github.com/ksmark/git-flow-test URL 에접속하면 commit/push 했던 README.md 파일을볼수있다. 또는 https://github.com/ksmark/git-flow-test/blob/master/readme.m d URL 에접속하면 commit 했던시간과파일정보를볼수있다. 04
SW 공학트렌드 동향분석 Webzine 2. GIT Flow Branch 전략 1) GIT Flow용 Repository로변경하기지금까지작업한것은 GIT Repository 를사용할수있는환경까지진행했다. GIT Flow Branch 전략의가장기본인 Master, Develop Branch 두개를사용할수있는환경, GIT Flow Branch 생성시 GIT Flow Branch 전략에맞게생성되고삭제되어야한다. GIT flow init 을실행하여 naming 에대한정책을지정할수있다. $ git flow init Which branch should be used for bringing forth production releases? - master 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 환경이되었는지 GIT Branch 명령어를통해확인한다. Develop Branch 의결과를보면 Master Branch 외에 Develop Branch가하나생겼고, 현재 Develop Branch로작업중이라고알려준다. Develop Branch 를 GIT Repository 에생성하여다른개발자들도모두볼수있도록한다. $ git branch * develop master $ git push origin develop Counting objects: 1, done. Writing objects: 100% (1/1), 249 bytes 0 bytes/s, done. Total 1 (delta 0), reused 0 (delta 0) To git@github.com:ksmark/git-flow-test.git * [new branch] develop -> develop.git/config 파일안에는 GIT Flow 관련처리내용이저장되어있다. 05 2014 February (No.83)
[branch "master"] remote = origin merge = refs/heads/master [gitflow "branch"] master = master develop = develop [gitflow "prefix"] feature = feature/ release = release/ hotfix = hotfix/ support = support/ versiontag = 2) Develop Branch 작업과 Push 개발 PC 상의 Develop Branch 상에서 pom.xml 파일을추가하고 commit 후 push 한다. $ touch pom.xml $ git status # On branch develop # Untracked files: # (use "git add <file>..." to include in what will be committed) # # pom.xml nothing added to commit but untracked files present (use "git add" to track) $ git add. $ git commit -m 'pom.xml added.' $ git push 3) GIT Flow Feature 사용하기 GIT Flow Feature 는 Develop Branch 기반위에만들어져기능단위의개발에유용하게사용한다. login-ui 라는이름으로 feature 를생성 (git flow feature start 'login-ui') 하고나면로컬 GIT Branch는자동으로해당 Branch로이동한다. $ git flow feature start 'login-ui' Switched to a new branch 'feature/login-ui' Summary of actions: - A new branch 'feature/login-ui' was created, based on 'develop' - You are now on branch 'feature/login-ui' 06
SW 공학트렌드 동향분석 Webzine Now, start committing on your feature. When done, use: git flow feature finish login-ui $ git branch develop * feature/login-ui master login-ui 관련작업을위해서 src 디렉토리에 3개의 png 파일과 login.js 파일을추가하고 login-ui branch 를 Develop Branch 로 Merge 한다. (git flow feature start 'login-ui') feature/login-ui branch 에서작업했던내용은 Develop Branch로 Merge 되고 Develop Branch는삭제된다. 그리고로컬 GIT Branch는 Develop 로이동한다. $ mkdir src $ touch src/login-ui1.png $ touch src/login-ui2.png $ touch src/login-ui3.png $ touch src/login.js $ git flow feature finish Switched to branch 'develop' Already up-to-date. Deleted branch feature/login-ui (was b3e057c). Summary of actions: - The feature branch 'feature/login-ui' was merged into 'develop' - Feature branch 'feature/login-ui' has been removed - You are now on branch 'develop' $ git branch * develop master $ git status # On branch develop # Untracked files: # (use "git add <file>..." to include in what will be committed) # 07 2014 February (No.83)
# src/ nothing added to commit but untracked files present (use "git add" to track) Develop Branch로 Merge 된내용을작업한내용모두를 Local Develop Branch에 commit 후 GIT Respository 에 Push 하여모두반영한다. $ git add. $ git commit -m 'login-ui commited.' [develop 85c849b] login-ui commited. 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/login-ui1.png create mode 100644 src/login-ui2.png create mode 100644 src/login-ui3.png create mode 100644 src/login.js $ git push 4) GIT Flow Release 사용하기 1.0.0 배포를위해서 1.0.0 Release Branch 를만든다. (git flow release start 1.0.0) 로컬 GIT Branch 는 Develop 에서 release/1.0.0 으로이동한다. 다른개발자와함께개발을동시에진행해야하기때문에서버에도 Branch 를생성한다.(git push origin release/1.0.0) $ git flow release start 1.0.0 Switched to a new branch 'release/1.0.0' Summary of actions: - A new branch 'release/1.0.0' was created, based on 'develop' - You are now on branch 'release/1.0.0' Follow-up actions: - Bump the version number now! - Start committing last-minute fixes in preparing your release - When done, run: git flow release finish '1.0.0' $ git branch develop master * release/1.0.0 08
SW 공학트렌드 동향분석 Webzine $ git push origin release/1.0.0 Counting objects: 6, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 527 bytes 0 bytes/s, done. Total 5 (delta 1), reused 0 (delta 0) To git@github.com:ksmark/git-flow-test.git * [new branch] release/1.0.0 -> release/1.0.0 배포버전 1.0.0 에서적용할작업내용을개발한다. $ mkdir login $ touch login/logincontroller.java $ touch login/loginservice.java $ touch login/loginrepository.java $ git add. $ git commit -m 'login logic added.' [release/1.0.0 6a2e09d] login logic added. 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 login/logincontroller.java create mode 100644 login/loginrepository.java create mode 100644 login/loginservice.java $ git push 기능단위로 commit & push 을진행한다. $ touch login/logoutcontroller.java $ git add. $ git commit -m 'log-out logic added.' [release/1.0.0 93529ca] log-out logic added. 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 login/logoutcontroller.java $ git push 개발작업이모두완료되면마무리를한다. (git flow release finish 1.0.0) Release Finish 시에는다음의순서대로차례로일어난다. - release/1.0.0 branch의최근소스가 Master Branch 에 Merge - 로컬에 tag 1.0.0 이생성 - release/1.0.0 branch 는 Develop Branch 로 Merge 됨 - 로컬의 release/1.0.0 는삭제됨 (Git Repository 에 push 된 release/1.0.0 은그대로존재 ) 09 2014 February (No.83)
$ git flow release finish 1.0.0 Switched to branch 'master' Merge made by the 'recursive' strategy. login/logoutcontroller.java 0 login/logincontroller.java 0 login/loginrepository.java 0 login/loginservice.java 0 pom.xml 0 src/login-ui1.png 0 src/login-ui2.png 0 src/login-ui3.png 0 src/login.js 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 login/logoutcontroller.java create mode 100644 login/logincontroller.java create mode 100644 login/loginrepository.java create mode 100644 login/loginservice.java create mode 100644 pom.xml create mode 100644 src/login-ui1.png create mode 100644 src/login-ui2.png create mode 100644 src/login-ui3.png create mode 100644 src/login.js Switched to branch 'develop' Merge made by the 'recursive' strategy. login/logoutcontroller.java 0 login/logincontroller.java 0 login/loginrepository.java 0 login/loginservice.java 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 login/logoutcontroller.java create mode 100644 login/logincontroller.java create mode 100644 login/loginrepository.java create mode 100644 login/loginservice.java Deleted branch release/1.0.0 (was 93529ca). Summary of actions: - Latest objects have been fetched from 'origin' - Release branch has been merged into 'master' - The release was tagged '1.0.0' 10
SW 공학트렌드 동향분석 Webzine - Release branch has been back-merged into 'develop' - Release branch 'release/1.0.0' has been deleted $ git branch * develop master Merge 된 Develop, Master Branch 와 tag 1.0.0 은모두로컬에있다. 이를모두 GIT Repository 에 push하여반영하여야한다. tag 와함께 push한다. $ git push $ git push --tags Counting objects: 1, done. Writing objects: 100% (1/1), 160 bytes 0 bytes/s, done. Total 1 (delta 0), reused 0 (delta 0) To git@github.com:ksmark/git-flow-test.git * [new tag] 1.0.0 -> 1.0.0 5) GIT Hotfix 사용하기 GIT Flow Release 와약간비슷한절차를거친다. 만약배포된버전인 Master Branch 에서버그가발생해서코드를고친후배포해야할상황에서사용한다. hotfix/1.0.1 branch 에긴급패치를진행한다. 로컬 GIT 은 hotfix/1.0.1 branch로자동으로이동한다. $ git flow hotfix start 1.0.1 Switched to a new branch 'hotfix/1.0.1' Summary of actions: - A new branch 'hotfix/1.0.1' was created, based on 'master' - You are now on branch 'hotfix/1.0.1' Follow-up actions: - Bump the version number now! - Start committing your hot fixes - When done, run: git flow hotfix finish '1.0.1' 11 2014 February (No.83)
$ git branch develop * hotfix/1.0.1 master Bug Fix 할소스를수정한후, commit & push를진행후에 Hotfix 를 Merge 한다. (GIT Flow Hotfix Finish) 작업한소스를가지고 Review 후에마무리를짓는다. $ vi login/logincontroller.java $ git add. $ git commit -m 'typo-critical issue fixed.' [hotfix/1.0.1 0356dcb] typo-critical issue fixed. 1 file changed, 1 insertion(+) $ git push Hotfix Branch 개발작업이모두완료되면마무리를한다. (git flow hotfix finish 1.0.1) Hotfix Finish 시에는다음의순서대로차례로일어난다. - hotfix/1.0.1 branch 의최근소스가모두 Master Branch 에 Merge 되고개발자가 Merge Log 를작성 - tag 는 1.0.1 이생성되고개발자가 Merge Log 작성 - Hotfix Branch 는 Develop 으로 Merge 되고개발자가 Merge Log 를작성 - 로컬의 hotfix branch 는삭제됨 (GIT repository 에 push 된 hotfix/1.0.1 은그대로존재 ) - Develop Branch로이동 $ git flow hotfix finish 1.0.1 Switched to branch 'master' Merge made by the 'recursive' strategy. login/logincontroller.java 1 + 1 file changed, 1 insertion(+) Switched to branch 'develop' Merge made by the 'recursive' strategy. login/logincontroller.java 1 + 1 file changed, 1 insertion(+) Deleted branch hotfix/1.0.1 (was 0356dcb). Summary of actions: - Latest objects have been fetched from 'origin' - Hotfix branch has been merged into 'master' - The hotfix was tagged '1.0.1' 12
SW 공학트렌드 동향분석 Webzine - Hotfix branch has been back-merged into 'develop' - Hotfix branch 'hotfix/1.0.1' has been deleted $ git branch * develop master Git Repository 에 tag 1.0.1 과 Develop, Master Branch 를반영한다. $ git push --tags $ git push 3. UI Tool 참고 지금까지의작업은터미널에서의작업으로터미널에서의명령어가익숙하지않을때는실수할수있는부분이존재한다. 이를위해서 < 그림 2> 의 Source Tree 라는오픈소스툴을활용하면 UI 를이용하여 GIT 과 GIT Flow 를쉽게이용할수있다. 그림 2_Source Tree App 스크린샷 출처 : http://www.sourcetreeapp.com/ 13 2014 February (No.83)
Ⅳ. 결론 지 금까지실습을통해서감을잡아보았다. Part 1에서언급한 GIT Flow 도식 < 그림4> 를다시살펴보기를권한다. GIT Flow 를사용하려면 Develop 와 Master Branch를활용해야한다. Feature Branch 전략을이용하면 Develop Branch에만영향을미치게되고, Release Branch 전략을이용하면 Master 와 Develop Branch 에차례로영향을미친다. Hotfix Branch 전략을사용하면 Release Branch 전략과비슷하게 Master 와 Develop Branch에영향을미친다. Release Branch 와 Hotfix Branch는버전을이용한 Branch이기때문에 tag 에정보가저장된다. GIT Flow 를통해배포관점의형상관리에대한실무활용에도움이되기를바란다. 참고자료 1. https://github.com/nvie/gitflow 2. http://nvie.com/posts/a-successful-git-branching-model/ 14