Git - 運用編

2012/05/14, DT Corp
 Naomichi Yamakita
概要


-   DTにおけるGitの基本開発サイクル

    1. 開発者はoriginからリポジトリのクローンを作成

    2. 各自の開発環境で開発を進め、変更内容をテストサーバに反映する

    3. テスト環境で動作確認

    4. ステージング環境にデプロイ

    5. プロダクション環境にデプロイ

    6. リリース完了

-   気軽にブランチを切れるため、ルールを決めないと混乱の元となる
運用ポリシー 1/2


-       開発リポジトリでは、仕様書や各種ドキュメント(議事録、見積書、デー
        タファイル等)を管理しない

    -    Redmine+Google Appsで一元管理

-       ファイル名は英語に統一する

    -    日本語ファイル名は、MacやLinux環境下で動作が不安定なため

    -    デベロッパーポータル: 基本原則: ファイルとディレクトリ
         http://project.svc-service.net/guideline/
         base_guideline.html#file_rule

-       Gitでは原則的にソースファイル(及び付随するAPI)のみを管理する
運用ポリシー 2/2


-   コミットメッセージに変更内容の概要を記す

-   コミット時に開発関係者へログメールが自動送信される

-   リポジトリの作成方法(DT社員のみ)

     $ cd /usr/local/git/repositories/
     $ su git
     $ git init --bare --shared=true {repository_name}.git
     Initialized empty shared Git repository in /usr/local/git/
     repositories/{repository_name}.git/

     $   cd ../gitosis-admin/
     $   vi gitosis.conf
     $   git commit -m “add {repository_name” -a
     $   git push
運用ポリシー 2/2


-   コミットメッセージに変更内容の概要を記す

-   コミット時に開発関係者へログメールが自動送信される

-   リポジトリの作成方法(DT社員のみ)

     $ cd /usr/local/git/repositories/
     $ su git
     $ git init --bare --shared=true {repository_name}.git
     Initialized empty shared Git repository in /usr/local/git/
     repositories/{repository_name}.git/
                                                共有リポジトリの設定
     $ cd ../gitosis-admin/
     $ vi gitosis.conf
     $ git commit -m “add {repository_name” -a
     $ git push
運用ポリシー 2/2


-   コミットメッセージに変更内容の概要を記す

-   コミット時に開発関係者へログメールが自動送信される

-   リポジトリの作成方法(DT社員のみ)

     $ cd /usr/local/git/repositories/
     $ su git
     $ git init --bare --shared=true {repository_name}.git
     Initialized empty shared Git repository in /usr/local/git/
     repositories/{repository_name}.git/
                                                共有リポジトリの設定
     $ cd ../gitosis-admin/
     $ vi gitosis.conf
     $ git commit -m “add {repository_name” -a
     $ git push
                         リポジトリのパーミッションを設定
DTが採用するGitの開発モデル


-       A successful Git branching model

    -        原文

         -    http://nvie.com/posts/a-successful-git-branching-model/

    -        日本語訳

         -    http://keijinsonyaban.blogspot.jp/2010/10/successful-git-
              branching-model.html
ブランチの種類


-       ブランチの種類

    -        メインブランチ

         -    master

         -    develop

    -        サポートブランチ

         -    feature

         -    release

         -    hotfix
メインブランチとは


-   中央リポジトリに存在し、削除されることなく永続的に保持される
ブランチの説明に入る前に


-   資料内でオレンジ色で書かれた内容はDT独自のローカルルールです
メインブランチの種類


-       master

    -        常にリリース可能状態

    -        開発では使用しない、タグ付け専用のブランチ

-       develop

    -        開発用途のブランチ

    -        開発完了後はmasterブランチへマージ

         -    この際にmasterブランチ上でタグ付けを行う
featureブランチとは


-       developとは別に並行開発をサポートするブランチを指す

    -    ここでの「並行開発」は、将来的に実装予定の機能やホットフィックス
         を含む

-       メインブランチと異なり、目的を達した後はブランチ自体破棄される

-       (原則的には)originサーバに存在しない
featureブランチの種類 1/3


-       fuature

    -         実験段階の機能を開発する際に使用する

    -         ブランチ特性

          -        分岐元: develop

          -        マージ先: develop

               -     場合によってはマージされず破棄されることもありうる

          -        ブランチ名の規則: fuature/{ticket_id}

               -     {ticket_id}: 対応するRedmineのチケットID
featureブランチの種類 2/3


-       release

    -         新しい機能をリリースする直前に使用する

    -         マイナーバグフィックスや最終調整はreleaseブランチで行う

    -         ブランチ特性

          -        分岐元: develop

          -        マージ先: developとmaster

               -     masterにマージする際はタグを付ける

          -        ブランチ名の規則: release/{yyyymmdd}
featureブランチの種類 3/3


-       hotfix

    -        リリース済みの製品におけるクリティカルなバグを修正する

         -        developブランチは他の機能を開発中で不安定な可能性がある

    -        ブランチ特性

         -        分岐元: master

         -        マージ先: developとmaster

              -     masterにマージする際はタグを付ける

              -     releaseが存在する場合はdevelopの代わりにreleaseにマージ

         -        ブランチ名の規則: hotfix/{yyyymmdd}_{ticket_id}
git-flow


-       A successful Git branching model のモデルを運用しやすくするプラグ
        イン

    -     https://github.com/nvie/gitflow

-       git-flowのセットアップ(Windows/Linux/Mac)

    -     http://www.oreilly.co.jp/community/blog/2011/11/branch-model-
          with-git-flow.html
git-flowの実行


-   リポジトリとブランチを作成する


     $ git flow init
     Initialized empty Git repository in /Users/naomichi/Desktop/
     testrep/.git/
     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 branch -a
     * develop
       master
git-flowの実行


-   リポジトリとブランチを作成する


     $ git flow init
     Initialized empty Git repository in /Users/naomichi/Desktop/
     testrep/.git/
     No branches exist yet. Base branches must be created now.
     Branch name for production releases: [master]
     Branch name for "next release" development: [develop]
                                          masterブランチ、featureブランチを命名
     How to name your supporting branch prefixes?
     Feature branches? [feature/]
     Release branches? [release/]
     Hotfix branches? [hotfix/]
     Support branches? [support/]
     Version tag prefix? []

     $ git branch -a
     * develop
       master
git-flowの実行


-   リポジトリとブランチを作成する


     $ git flow init
     Initialized empty Git repository in /Users/naomichi/Desktop/
     testrep/.git/
     No branches exist yet. Base branches must be created now.
     Branch name for production releases: [master]
     Branch name for "next release" development: [develop]
                                          masterブランチ、featureブランチを命名
     How to name your supporting branch prefixes?
     Feature branches? [feature/]
     Release branches? [release/]
     Hotfix branches? [hotfix/]
     Support branches? [support/]
     Version tag prefix? []

     $ git branch -a
     * develop
       master
                       featureブランチは表示されない(後述)
featureブランチの作成 1/2


-   新機能の開発を開始する


     $ echo 'hello' > greeting
     $ git add .
     $ git commit -m "first commit"

     $ git flow feature start 100
     Switched to a new branch 'feature/100'

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

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

          git flow feature finish 100

     $ git branch
       develop
     * feature/100
       master
featureブランチの作成 1/2


-   新機能の開発を開始する


     $ echo 'hello' > greeting           Redmine#100の開発を開始
     $ git add .
     $ git commit -m "first commit"

     $ git flow feature start 100
     Switched to a new branch 'feature/100'

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

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

          git flow feature finish 100

     $ git branch
       develop
     * feature/100
       master
featureブランチの作成 1/2


-   新機能の開発を開始する


     $ echo 'hello' > greeting           Redmine#100の開発を開始
     $ git add .
     $ git commit -m "first commit"

     $ git flow feature start 100
     Switched to a new branch 'feature/100'

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

     Now, start committing on your feature. When done, use:
                                     developブランチを元にfeatureブランチが作成された
          git flow feature finish 100

     $ git branch
       develop
     * feature/100
       master
featureブランチの作成 1/2


-   新機能の開発を開始する


     $ echo 'hello' > greeting           Redmine#100の開発を開始
     $ git add .
     $ git commit -m "first commit"

     $ git flow feature start 100
     Switched to a new branch 'feature/100'

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

     Now, start committing on your feature. When done, use:
                                     developブランチを元にfeatureブランチが作成された
          git flow feature finish 100

     $ git branch
       develop
     * feature/100
       master
                      ブランチが追加される
featureブランチの作成 2/2


-   featureの開発を終わらせてdevelopに戻る(マージする)


     $ echo 'good night' > greeting
     $ git commit -m "second commit" -a

     $ git flow feature finish 100
     Switched to branch 'develop'
     Updating 01f0874..58f1c0d
     Fast-forward
      greeting |    2 +-
      1 files changed, 1 insertions(+), 1 deletions(-)
     Deleted branch feature/100 (was 58f1c0d).

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

     $ cat greeting
     good night

     $ git branch
     * develop
       master
featureブランチの作成 2/2


-   featureの開発を終わらせてdevelopに戻る(マージする)

                                      featureブランチの終わりを宣言
     $ echo 'good night' > greeting
     $ git commit -m "second commit" -a

     $ git flow feature finish 100
     Switched to branch 'develop'
     Updating 01f0874..58f1c0d
     Fast-forward
      greeting |    2 +-
      1 files changed, 1 insertions(+), 1 deletions(-)
     Deleted branch feature/100 (was 58f1c0d).

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

     $ cat greeting
     good night

     $ git branch
     * develop
       master
featureブランチの作成 2/2


-   featureの開発を終わらせてdevelopに戻る(マージする)

                                      featureブランチの終わりを宣言
     $ echo 'good night' > greeting
     $ git commit -m "second commit" -a

     $ git flow feature finish 100
     Switched to branch 'develop'
     Updating 01f0874..58f1c0d
     Fast-forward
      greeting |    2 +-   developブランチにマージされ、featureブランチが削除される
      1 files changed, 1 insertions(+), 1 deletions(-)
     Deleted branch feature/100 (was 58f1c0d).

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

     $ cat greeting
     good night

     $ git branch
     * develop
       master
featureブランチの作成 2/2


-   featureの開発を終わらせてdevelopに戻る(マージする)

                                      featureブランチの終わりを宣言
     $ echo 'good night' > greeting
     $ git commit -m "second commit" -a

     $ git flow feature finish 100
     Switched to branch 'develop'
     Updating 01f0874..58f1c0d
     Fast-forward
      greeting |    2 +-   developブランチにマージされ、featureブランチが削除される
      1 files changed, 1 insertions(+), 1 deletions(-)
     Deleted branch feature/100 (was 58f1c0d).

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

     $ cat greeting
     good night         developブランチにマージされたことが確認できる

     $ git branch
     * develop
       master
featureブランチの作成 2/2


-   featureの開発を終わらせてdevelopに戻る(マージする)

                                      featureブランチの終わりを宣言
     $ echo 'good night' > greeting
     $ git commit -m "second commit" -a

     $ git flow feature finish 100
     Switched to branch 'develop'
     Updating 01f0874..58f1c0d
     Fast-forward
      greeting |    2 +-   developブランチにマージされ、featureブランチが削除される
      1 files changed, 1 insertions(+), 1 deletions(-)
     Deleted branch feature/100 (was 58f1c0d).

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

     $ cat greeting
     good night         developブランチにマージされたことが確認できる

     $ git branch
     * develop          featureブランチは削除済み
       master
releaseブランチの作成 1/2


-   リリースバージョンを作成

     $ git flow release start 20120401
     Switched to a new branch 'release/20120401'

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

     Follow-up actions:
     - Bump the version number now!
     - Start committing last-minute fixes in preparing your release
     - When done, run:

          git flow release finish '20120401'

     $ git branch
       develop
       master
     * release/20120401
releaseブランチの作成 1/2


-   リリースバージョンを作成

     $ git flow release start 20120401              releaseブランチを開始
     Switched to a new branch 'release/20120401'

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

     Follow-up actions:
     - Bump the version number now!
     - Start committing last-minute fixes in preparing your release
     - When done, run:

          git flow release finish '20120401'

     $ git branch
       develop
       master
     * release/20120401
releaseブランチの作成 1/2


-   リリースバージョンを作成

     $ git flow release start 20120401              releaseブランチを開始
     Switched to a new branch 'release/20120401'

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

     Follow-up actions:
     - Bump the version number now! developブランチを元にreleaseブランチが作成された
     - Start committing last-minute fixes in preparing your release
     - When done, run:

          git flow release finish '20120401'

     $ git branch
       develop
       master
     * release/20120401
releaseブランチの作成 1/2


-   リリースバージョンを作成

     $ git flow release start 20120401              releaseブランチを開始
     Switched to a new branch 'release/20120401'

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

     Follow-up actions:
     - Bump the version number now! developブランチを元にreleaseブランチが作成された
     - Start committing last-minute fixes in preparing your release
     - When done, run:

          git flow release finish '20120401'

     $ git branch
       develop              releaseブランチがアクティブになる
       master
     * release/20120401
releaseブランチの作成 2/2


-   プログラムの微調整を加えた後にリリースを行う

     $ echo 'good mornink'
     good mornink
     $ git commit -m "first commit"

     $ git flow release finish 1.0
     Switched to branch 'master'
     Merge made by recursive.
      greeting |    1 +
      1 files changed, 1 insertions(+), 0 deletions(-)
      create mode 100644 greeting
      create mode 100644 hello
      Deleted branch release/1.0 (was 58f1c0d).

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

     [naomichi: test]$ git tag
     20120401
releaseブランチの作成 2/2


-   プログラムの微調整を加えた後にリリースを行う

     $ echo 'good mornink'
     good mornink
     $ git commit -m "first commit"

     $ git flow release finish 1.0
     Switched to branch 'master'
     Merge made by recursive.
      greeting |    1 +
      1 files changed, 1 insertions(+), 0 deletions(-)
      create mode 100644 greeting
                          releaseブランチを終了し、master/developブランチにマージする
      create mode 100644 hello
      Deleted branch release/1.0 (was 58f1c0d).

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

     [naomichi: test]$ git tag
     20120401
releaseブランチの作成 2/2


-   プログラムの微調整を加えた後にリリースを行う

     $ echo 'good mornink'
     good mornink
     $ git commit -m "first commit"

     $ git flow release finish 1.0
     Switched to branch 'master'
     Merge made by recursive.
      greeting |    1 +
      1 files changed, 1 insertions(+), 0 deletions(-)
      create mode 100644 greeting
                          releaseブランチを終了し、master/developブランチにマージする
      create mode 100644 hello
      Deleted branch release/1.0 (was 58f1c0d).

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

     [naomichi: test]$ git tag
     20120401              マージとmasterブランチへのタグ付けが行われた
hotfixブランチの作成 1/2


-   リリース済みのプログラムに対し修正を加える


     $ git flow hotfix start 20120401_200
     Switched to a new branch 'hotfix/20120401_200'

     Summary of actions:
     - A new branch 'hotfix/20120401_200' was created, based on
     'master'
     - You are now on branch 'hotfix/20120401_200'

     Follow-up actions:
     - Bump the version number now!
     - Start committing your hot fixes
     - When done, run:

          git flow hotfix finish '20120401_200'

     $ git branch
       develop
     * hotfix/20120401_200
       master
hotfixブランチの作成 1/2


-   リリース済みのプログラムに対し修正を加える
                                                  Redmine#200のホットフィックスを開始


     $ git flow hotfix start 20120401_200
     Switched to a new branch 'hotfix/20120401_200'

     Summary of actions:
     - A new branch 'hotfix/20120401_200' was created, based on
     'master'
     - You are now on branch 'hotfix/20120401_200'

     Follow-up actions:
     - Bump the version number now!
     - Start committing your hot fixes
     - When done, run:

          git flow hotfix finish '20120401_200'

     $ git branch
       develop
     * hotfix/20120401_200
       master
hotfixブランチの作成 1/2


-   リリース済みのプログラムに対し修正を加える
                                                  Redmine#200のホットフィックスを開始


     $ git flow hotfix start 20120401_200
     Switched to a new branch 'hotfix/20120401_200'

     Summary of actions:
     - A new branch 'hotfix/20120401_200' was created, based on
     'master'
     - You are now on branch 'hotfix/20120401_200'

     Follow-up actions:
     - Bump the version number now!    masterブランチを元にhotfixブランチを作成
     - Start committing your hot fixes
     - When done, run:

          git flow hotfix finish '20120401_200'

     $ git branch
       develop
     * hotfix/20120401_200
       master
hotfixブランチの作成 1/2


-   リリース済みのプログラムに対し修正を加える
                                                  Redmine#200のホットフィックスを開始


     $ git flow hotfix start 20120401_200
     Switched to a new branch 'hotfix/20120401_200'

     Summary of actions:
     - A new branch 'hotfix/20120401_200' was created, based on
     'master'
     - You are now on branch 'hotfix/20120401_200'

     Follow-up actions:
     - Bump the version number now!    masterブランチを元にhotfixブランチを作成
     - Start committing your hot fixes
     - When done, run:

          git flow hotfix finish '20120401_200'

     $ git branch
       develop                 hotfixブランチが追加される
     * hotfix/20120401_200
       master
hotfixブランチの作成 2/2


-   ホットフィックスの適用


     $ echo 'good night' > greeting
     $ git commit -m "fixed spell" -a
     # On branch hotfix/20120401_200
     nothing to commit (working directory clean)

     $ git flow hotfix finish 20120401_200
     Switched to branch 'develop'
     Already up-to-date!
     Merge made by recursive.
     Deleted branch hotfix/20120401_200 (was 8aeddfd).

     Summary of actions:
     - Latest objects have been fetched from 'origin'
     - Hotfix branch has been merged into 'master'
     - The hotfix was tagged '20120401_200'
     - Hotfix branch has been back-merged into 'develop'
     - Hotfix branch 'hotfix/20120401_200' has been deleted
hotfixブランチの作成 2/2


-   ホットフィックスの適用


     $ echo 'good night' > greeting
     $ git commit -m "fixed spell" -a
     # On branch hotfix/20120401_200   スペルミスを修正してコミット
     nothing to commit (working directory clean)

     $ git flow hotfix finish 20120401_200
     Switched to branch 'develop'
     Already up-to-date!
     Merge made by recursive.
     Deleted branch hotfix/20120401_200 (was 8aeddfd).

     Summary of actions:
     - Latest objects have been fetched from 'origin'
     - Hotfix branch has been merged into 'master'
     - The hotfix was tagged '20120401_200'
     - Hotfix branch has been back-merged into 'develop'
     - Hotfix branch 'hotfix/20120401_200' has been deleted
hotfixブランチの作成 2/2


-   ホットフィックスの適用


     $ echo 'good night' > greeting
     $ git commit -m "fixed spell" -a
     # On branch hotfix/20120401_200   スペルミスを修正してコミット
     nothing to commit (working directory clean)

     $ git flow hotfix finish 20120401_200
     Switched to branch 'develop'
     Already up-to-date!
     Merge made by recursive.        ホットフィックスを終わらせる
     Deleted branch hotfix/20120401_200 (was 8aeddfd).

     Summary of actions:
     - Latest objects have been fetched from 'origin'
     - Hotfix branch has been merged into 'master'
     - The hotfix was tagged '20120401_200'
     - Hotfix branch has been back-merged into 'develop'
     - Hotfix branch 'hotfix/20120401_200' has been deleted
hotfixブランチの作成 2/2


-   ホットフィックスの適用


     $ echo 'good night' > greeting
     $ git commit -m "fixed spell" -a
     # On branch hotfix/20120401_200   スペルミスを修正してコミット
     nothing to commit (working directory clean)

     $ git flow hotfix finish 20120401_200
     Switched to branch 'develop'
     Already up-to-date!
     Merge made by recursive.        ホットフィックスを終わらせる
     Deleted branch hotfix/20120401_200 (was 8aeddfd).

     Summary of actions:
     - Latest objects have been fetched from 'origin'
     - Hotfix branch has been merged into 'master'
     - The hotfix was tagged '20120401_200'
     - Hotfix branch has been back-merged into 'develop'
     - Hotfix branch 'hotfix/20120401_200' has been deleted


                               ホットフィックスをmaster/developブランチに反映
今後の運用方針案


-       コミット時にRedmineのチケットIDを必須とする

    -    変更内容とチケットを紐付けることで、変更の流れが掴みやすくなる

-       コミットフックでPHPのシンタックスチェック

Git (運用編)

  • 1.
    Git - 運用編 2012/05/14,DT Corp Naomichi Yamakita
  • 2.
    概要 - DTにおけるGitの基本開発サイクル 1. 開発者はoriginからリポジトリのクローンを作成 2. 各自の開発環境で開発を進め、変更内容をテストサーバに反映する 3. テスト環境で動作確認 4. ステージング環境にデプロイ 5. プロダクション環境にデプロイ 6. リリース完了 - 気軽にブランチを切れるため、ルールを決めないと混乱の元となる
  • 3.
    運用ポリシー 1/2 - 開発リポジトリでは、仕様書や各種ドキュメント(議事録、見積書、デー タファイル等)を管理しない - Redmine+Google Appsで一元管理 - ファイル名は英語に統一する - 日本語ファイル名は、MacやLinux環境下で動作が不安定なため - デベロッパーポータル: 基本原則: ファイルとディレクトリ http://project.svc-service.net/guideline/ base_guideline.html#file_rule - Gitでは原則的にソースファイル(及び付随するAPI)のみを管理する
  • 4.
    運用ポリシー 2/2 - コミットメッセージに変更内容の概要を記す - コミット時に開発関係者へログメールが自動送信される - リポジトリの作成方法(DT社員のみ) $ cd /usr/local/git/repositories/ $ su git $ git init --bare --shared=true {repository_name}.git Initialized empty shared Git repository in /usr/local/git/ repositories/{repository_name}.git/ $ cd ../gitosis-admin/ $ vi gitosis.conf $ git commit -m “add {repository_name” -a $ git push
  • 5.
    運用ポリシー 2/2 - コミットメッセージに変更内容の概要を記す - コミット時に開発関係者へログメールが自動送信される - リポジトリの作成方法(DT社員のみ) $ cd /usr/local/git/repositories/ $ su git $ git init --bare --shared=true {repository_name}.git Initialized empty shared Git repository in /usr/local/git/ repositories/{repository_name}.git/ 共有リポジトリの設定 $ cd ../gitosis-admin/ $ vi gitosis.conf $ git commit -m “add {repository_name” -a $ git push
  • 6.
    運用ポリシー 2/2 - コミットメッセージに変更内容の概要を記す - コミット時に開発関係者へログメールが自動送信される - リポジトリの作成方法(DT社員のみ) $ cd /usr/local/git/repositories/ $ su git $ git init --bare --shared=true {repository_name}.git Initialized empty shared Git repository in /usr/local/git/ repositories/{repository_name}.git/ 共有リポジトリの設定 $ cd ../gitosis-admin/ $ vi gitosis.conf $ git commit -m “add {repository_name” -a $ git push リポジトリのパーミッションを設定
  • 7.
    DTが採用するGitの開発モデル - A successful Git branching model - 原文 - http://nvie.com/posts/a-successful-git-branching-model/ - 日本語訳 - http://keijinsonyaban.blogspot.jp/2010/10/successful-git- branching-model.html
  • 8.
    ブランチの種類 - ブランチの種類 - メインブランチ - master - develop - サポートブランチ - feature - release - hotfix
  • 9.
    メインブランチとは - 中央リポジトリに存在し、削除されることなく永続的に保持される
  • 10.
    ブランチの説明に入る前に - 資料内でオレンジ色で書かれた内容はDT独自のローカルルールです
  • 11.
    メインブランチの種類 - master - 常にリリース可能状態 - 開発では使用しない、タグ付け専用のブランチ - develop - 開発用途のブランチ - 開発完了後はmasterブランチへマージ - この際にmasterブランチ上でタグ付けを行う
  • 12.
    featureブランチとは - developとは別に並行開発をサポートするブランチを指す - ここでの「並行開発」は、将来的に実装予定の機能やホットフィックス を含む - メインブランチと異なり、目的を達した後はブランチ自体破棄される - (原則的には)originサーバに存在しない
  • 13.
    featureブランチの種類 1/3 - fuature - 実験段階の機能を開発する際に使用する - ブランチ特性 - 分岐元: develop - マージ先: develop - 場合によってはマージされず破棄されることもありうる - ブランチ名の規則: fuature/{ticket_id} - {ticket_id}: 対応するRedmineのチケットID
  • 14.
    featureブランチの種類 2/3 - release - 新しい機能をリリースする直前に使用する - マイナーバグフィックスや最終調整はreleaseブランチで行う - ブランチ特性 - 分岐元: develop - マージ先: developとmaster - masterにマージする際はタグを付ける - ブランチ名の規則: release/{yyyymmdd}
  • 15.
    featureブランチの種類 3/3 - hotfix - リリース済みの製品におけるクリティカルなバグを修正する - developブランチは他の機能を開発中で不安定な可能性がある - ブランチ特性 - 分岐元: master - マージ先: developとmaster - masterにマージする際はタグを付ける - releaseが存在する場合はdevelopの代わりにreleaseにマージ - ブランチ名の規則: hotfix/{yyyymmdd}_{ticket_id}
  • 16.
    git-flow - A successful Git branching model のモデルを運用しやすくするプラグ イン - https://github.com/nvie/gitflow - git-flowのセットアップ(Windows/Linux/Mac) - http://www.oreilly.co.jp/community/blog/2011/11/branch-model- with-git-flow.html
  • 17.
    git-flowの実行 - リポジトリとブランチを作成する $ git flow init Initialized empty Git repository in /Users/naomichi/Desktop/ testrep/.git/ 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 branch -a * develop master
  • 18.
    git-flowの実行 - リポジトリとブランチを作成する $ git flow init Initialized empty Git repository in /Users/naomichi/Desktop/ testrep/.git/ No branches exist yet. Base branches must be created now. Branch name for production releases: [master] Branch name for "next release" development: [develop] masterブランチ、featureブランチを命名 How to name your supporting branch prefixes? Feature branches? [feature/] Release branches? [release/] Hotfix branches? [hotfix/] Support branches? [support/] Version tag prefix? [] $ git branch -a * develop master
  • 19.
    git-flowの実行 - リポジトリとブランチを作成する $ git flow init Initialized empty Git repository in /Users/naomichi/Desktop/ testrep/.git/ No branches exist yet. Base branches must be created now. Branch name for production releases: [master] Branch name for "next release" development: [develop] masterブランチ、featureブランチを命名 How to name your supporting branch prefixes? Feature branches? [feature/] Release branches? [release/] Hotfix branches? [hotfix/] Support branches? [support/] Version tag prefix? [] $ git branch -a * develop master featureブランチは表示されない(後述)
  • 20.
    featureブランチの作成 1/2 - 新機能の開発を開始する $ echo 'hello' > greeting $ git add . $ git commit -m "first commit" $ git flow feature start 100 Switched to a new branch 'feature/100' Summary of actions: - A new branch 'feature/100' was created, based on 'develop' - You are now on branch 'feature/100' Now, start committing on your feature. When done, use: git flow feature finish 100 $ git branch develop * feature/100 master
  • 21.
    featureブランチの作成 1/2 - 新機能の開発を開始する $ echo 'hello' > greeting Redmine#100の開発を開始 $ git add . $ git commit -m "first commit" $ git flow feature start 100 Switched to a new branch 'feature/100' Summary of actions: - A new branch 'feature/100' was created, based on 'develop' - You are now on branch 'feature/100' Now, start committing on your feature. When done, use: git flow feature finish 100 $ git branch develop * feature/100 master
  • 22.
    featureブランチの作成 1/2 - 新機能の開発を開始する $ echo 'hello' > greeting Redmine#100の開発を開始 $ git add . $ git commit -m "first commit" $ git flow feature start 100 Switched to a new branch 'feature/100' Summary of actions: - A new branch 'feature/100' was created, based on 'develop' - You are now on branch 'feature/100' Now, start committing on your feature. When done, use: developブランチを元にfeatureブランチが作成された git flow feature finish 100 $ git branch develop * feature/100 master
  • 23.
    featureブランチの作成 1/2 - 新機能の開発を開始する $ echo 'hello' > greeting Redmine#100の開発を開始 $ git add . $ git commit -m "first commit" $ git flow feature start 100 Switched to a new branch 'feature/100' Summary of actions: - A new branch 'feature/100' was created, based on 'develop' - You are now on branch 'feature/100' Now, start committing on your feature. When done, use: developブランチを元にfeatureブランチが作成された git flow feature finish 100 $ git branch develop * feature/100 master ブランチが追加される
  • 24.
    featureブランチの作成 2/2 - featureの開発を終わらせてdevelopに戻る(マージする) $ echo 'good night' > greeting $ git commit -m "second commit" -a $ git flow feature finish 100 Switched to branch 'develop' Updating 01f0874..58f1c0d Fast-forward greeting | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) Deleted branch feature/100 (was 58f1c0d). Summary of actions: - The feature branch 'feature/100' was merged into 'develop' - Feature branch 'feature/100' has been removed - You are now on branch 'develop' $ cat greeting good night $ git branch * develop master
  • 25.
    featureブランチの作成 2/2 - featureの開発を終わらせてdevelopに戻る(マージする) featureブランチの終わりを宣言 $ echo 'good night' > greeting $ git commit -m "second commit" -a $ git flow feature finish 100 Switched to branch 'develop' Updating 01f0874..58f1c0d Fast-forward greeting | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) Deleted branch feature/100 (was 58f1c0d). Summary of actions: - The feature branch 'feature/100' was merged into 'develop' - Feature branch 'feature/100' has been removed - You are now on branch 'develop' $ cat greeting good night $ git branch * develop master
  • 26.
    featureブランチの作成 2/2 - featureの開発を終わらせてdevelopに戻る(マージする) featureブランチの終わりを宣言 $ echo 'good night' > greeting $ git commit -m "second commit" -a $ git flow feature finish 100 Switched to branch 'develop' Updating 01f0874..58f1c0d Fast-forward greeting | 2 +- developブランチにマージされ、featureブランチが削除される 1 files changed, 1 insertions(+), 1 deletions(-) Deleted branch feature/100 (was 58f1c0d). Summary of actions: - The feature branch 'feature/100' was merged into 'develop' - Feature branch 'feature/100' has been removed - You are now on branch 'develop' $ cat greeting good night $ git branch * develop master
  • 27.
    featureブランチの作成 2/2 - featureの開発を終わらせてdevelopに戻る(マージする) featureブランチの終わりを宣言 $ echo 'good night' > greeting $ git commit -m "second commit" -a $ git flow feature finish 100 Switched to branch 'develop' Updating 01f0874..58f1c0d Fast-forward greeting | 2 +- developブランチにマージされ、featureブランチが削除される 1 files changed, 1 insertions(+), 1 deletions(-) Deleted branch feature/100 (was 58f1c0d). Summary of actions: - The feature branch 'feature/100' was merged into 'develop' - Feature branch 'feature/100' has been removed - You are now on branch 'develop' $ cat greeting good night developブランチにマージされたことが確認できる $ git branch * develop master
  • 28.
    featureブランチの作成 2/2 - featureの開発を終わらせてdevelopに戻る(マージする) featureブランチの終わりを宣言 $ echo 'good night' > greeting $ git commit -m "second commit" -a $ git flow feature finish 100 Switched to branch 'develop' Updating 01f0874..58f1c0d Fast-forward greeting | 2 +- developブランチにマージされ、featureブランチが削除される 1 files changed, 1 insertions(+), 1 deletions(-) Deleted branch feature/100 (was 58f1c0d). Summary of actions: - The feature branch 'feature/100' was merged into 'develop' - Feature branch 'feature/100' has been removed - You are now on branch 'develop' $ cat greeting good night developブランチにマージされたことが確認できる $ git branch * develop featureブランチは削除済み master
  • 29.
    releaseブランチの作成 1/2 - リリースバージョンを作成 $ git flow release start 20120401 Switched to a new branch 'release/20120401' Summary of actions: - A new branch 'release/20120401' was created, based on 'develop' - You are now on branch 'release/20120401' Follow-up actions: - Bump the version number now! - Start committing last-minute fixes in preparing your release - When done, run: git flow release finish '20120401' $ git branch develop master * release/20120401
  • 30.
    releaseブランチの作成 1/2 - リリースバージョンを作成 $ git flow release start 20120401 releaseブランチを開始 Switched to a new branch 'release/20120401' Summary of actions: - A new branch 'release/20120401' was created, based on 'develop' - You are now on branch 'release/20120401' Follow-up actions: - Bump the version number now! - Start committing last-minute fixes in preparing your release - When done, run: git flow release finish '20120401' $ git branch develop master * release/20120401
  • 31.
    releaseブランチの作成 1/2 - リリースバージョンを作成 $ git flow release start 20120401 releaseブランチを開始 Switched to a new branch 'release/20120401' Summary of actions: - A new branch 'release/20120401' was created, based on 'develop' - You are now on branch 'release/20120401' Follow-up actions: - Bump the version number now! developブランチを元にreleaseブランチが作成された - Start committing last-minute fixes in preparing your release - When done, run: git flow release finish '20120401' $ git branch develop master * release/20120401
  • 32.
    releaseブランチの作成 1/2 - リリースバージョンを作成 $ git flow release start 20120401 releaseブランチを開始 Switched to a new branch 'release/20120401' Summary of actions: - A new branch 'release/20120401' was created, based on 'develop' - You are now on branch 'release/20120401' Follow-up actions: - Bump the version number now! developブランチを元にreleaseブランチが作成された - Start committing last-minute fixes in preparing your release - When done, run: git flow release finish '20120401' $ git branch develop releaseブランチがアクティブになる master * release/20120401
  • 33.
    releaseブランチの作成 2/2 - プログラムの微調整を加えた後にリリースを行う $ echo 'good mornink' good mornink $ git commit -m "first commit" $ git flow release finish 1.0 Switched to branch 'master' Merge made by recursive. greeting | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 greeting create mode 100644 hello Deleted branch release/1.0 (was 58f1c0d). Summary of actions: - Latest objects have been fetched from 'origin' - Release branch has been merged into 'master' - The release was tagged '1.0' - Release branch has been back-merged into 'develop' - Release branch 'release/1.0' has been deleted [naomichi: test]$ git tag 20120401
  • 34.
    releaseブランチの作成 2/2 - プログラムの微調整を加えた後にリリースを行う $ echo 'good mornink' good mornink $ git commit -m "first commit" $ git flow release finish 1.0 Switched to branch 'master' Merge made by recursive. greeting | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 greeting releaseブランチを終了し、master/developブランチにマージする create mode 100644 hello Deleted branch release/1.0 (was 58f1c0d). Summary of actions: - Latest objects have been fetched from 'origin' - Release branch has been merged into 'master' - The release was tagged '1.0' - Release branch has been back-merged into 'develop' - Release branch 'release/1.0' has been deleted [naomichi: test]$ git tag 20120401
  • 35.
    releaseブランチの作成 2/2 - プログラムの微調整を加えた後にリリースを行う $ echo 'good mornink' good mornink $ git commit -m "first commit" $ git flow release finish 1.0 Switched to branch 'master' Merge made by recursive. greeting | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 greeting releaseブランチを終了し、master/developブランチにマージする create mode 100644 hello Deleted branch release/1.0 (was 58f1c0d). Summary of actions: - Latest objects have been fetched from 'origin' - Release branch has been merged into 'master' - The release was tagged '1.0' - Release branch has been back-merged into 'develop' - Release branch 'release/1.0' has been deleted [naomichi: test]$ git tag 20120401 マージとmasterブランチへのタグ付けが行われた
  • 36.
    hotfixブランチの作成 1/2 - リリース済みのプログラムに対し修正を加える $ git flow hotfix start 20120401_200 Switched to a new branch 'hotfix/20120401_200' Summary of actions: - A new branch 'hotfix/20120401_200' was created, based on 'master' - You are now on branch 'hotfix/20120401_200' Follow-up actions: - Bump the version number now! - Start committing your hot fixes - When done, run: git flow hotfix finish '20120401_200' $ git branch develop * hotfix/20120401_200 master
  • 37.
    hotfixブランチの作成 1/2 - リリース済みのプログラムに対し修正を加える Redmine#200のホットフィックスを開始 $ git flow hotfix start 20120401_200 Switched to a new branch 'hotfix/20120401_200' Summary of actions: - A new branch 'hotfix/20120401_200' was created, based on 'master' - You are now on branch 'hotfix/20120401_200' Follow-up actions: - Bump the version number now! - Start committing your hot fixes - When done, run: git flow hotfix finish '20120401_200' $ git branch develop * hotfix/20120401_200 master
  • 38.
    hotfixブランチの作成 1/2 - リリース済みのプログラムに対し修正を加える Redmine#200のホットフィックスを開始 $ git flow hotfix start 20120401_200 Switched to a new branch 'hotfix/20120401_200' Summary of actions: - A new branch 'hotfix/20120401_200' was created, based on 'master' - You are now on branch 'hotfix/20120401_200' Follow-up actions: - Bump the version number now! masterブランチを元にhotfixブランチを作成 - Start committing your hot fixes - When done, run: git flow hotfix finish '20120401_200' $ git branch develop * hotfix/20120401_200 master
  • 39.
    hotfixブランチの作成 1/2 - リリース済みのプログラムに対し修正を加える Redmine#200のホットフィックスを開始 $ git flow hotfix start 20120401_200 Switched to a new branch 'hotfix/20120401_200' Summary of actions: - A new branch 'hotfix/20120401_200' was created, based on 'master' - You are now on branch 'hotfix/20120401_200' Follow-up actions: - Bump the version number now! masterブランチを元にhotfixブランチを作成 - Start committing your hot fixes - When done, run: git flow hotfix finish '20120401_200' $ git branch develop hotfixブランチが追加される * hotfix/20120401_200 master
  • 40.
    hotfixブランチの作成 2/2 - ホットフィックスの適用 $ echo 'good night' > greeting $ git commit -m "fixed spell" -a # On branch hotfix/20120401_200 nothing to commit (working directory clean) $ git flow hotfix finish 20120401_200 Switched to branch 'develop' Already up-to-date! Merge made by recursive. Deleted branch hotfix/20120401_200 (was 8aeddfd). Summary of actions: - Latest objects have been fetched from 'origin' - Hotfix branch has been merged into 'master' - The hotfix was tagged '20120401_200' - Hotfix branch has been back-merged into 'develop' - Hotfix branch 'hotfix/20120401_200' has been deleted
  • 41.
    hotfixブランチの作成 2/2 - ホットフィックスの適用 $ echo 'good night' > greeting $ git commit -m "fixed spell" -a # On branch hotfix/20120401_200 スペルミスを修正してコミット nothing to commit (working directory clean) $ git flow hotfix finish 20120401_200 Switched to branch 'develop' Already up-to-date! Merge made by recursive. Deleted branch hotfix/20120401_200 (was 8aeddfd). Summary of actions: - Latest objects have been fetched from 'origin' - Hotfix branch has been merged into 'master' - The hotfix was tagged '20120401_200' - Hotfix branch has been back-merged into 'develop' - Hotfix branch 'hotfix/20120401_200' has been deleted
  • 42.
    hotfixブランチの作成 2/2 - ホットフィックスの適用 $ echo 'good night' > greeting $ git commit -m "fixed spell" -a # On branch hotfix/20120401_200 スペルミスを修正してコミット nothing to commit (working directory clean) $ git flow hotfix finish 20120401_200 Switched to branch 'develop' Already up-to-date! Merge made by recursive. ホットフィックスを終わらせる Deleted branch hotfix/20120401_200 (was 8aeddfd). Summary of actions: - Latest objects have been fetched from 'origin' - Hotfix branch has been merged into 'master' - The hotfix was tagged '20120401_200' - Hotfix branch has been back-merged into 'develop' - Hotfix branch 'hotfix/20120401_200' has been deleted
  • 43.
    hotfixブランチの作成 2/2 - ホットフィックスの適用 $ echo 'good night' > greeting $ git commit -m "fixed spell" -a # On branch hotfix/20120401_200 スペルミスを修正してコミット nothing to commit (working directory clean) $ git flow hotfix finish 20120401_200 Switched to branch 'develop' Already up-to-date! Merge made by recursive. ホットフィックスを終わらせる Deleted branch hotfix/20120401_200 (was 8aeddfd). Summary of actions: - Latest objects have been fetched from 'origin' - Hotfix branch has been merged into 'master' - The hotfix was tagged '20120401_200' - Hotfix branch has been back-merged into 'develop' - Hotfix branch 'hotfix/20120401_200' has been deleted ホットフィックスをmaster/developブランチに反映
  • 44.
    今後の運用方針案 - コミット時にRedmineのチケットIDを必須とする - 変更内容とチケットを紐付けることで、変更の流れが掴みやすくなる - コミットフックでPHPのシンタックスチェック

Editor's Notes

  • #2 \n
  • #3 \n
  • #4 \n
  • #5 \n
  • #6 \n
  • #7 \n
  • #8 \n
  • #9 \n
  • #10 \n
  • #11 \n
  • #12 \n
  • #13 \n
  • #14 ・releaseブランチで大きな変更を加えてはならない\n
  • #15 \n
  • #16 \n
  • #17 \n
  • #18 \n
  • #19 ・featureブランチは並行で複数作成される可能性もある\n
  • #20 ・featureブランチは並行で複数作成される可能性もある\n
  • #21 ・featureブランチは並行で複数作成される可能性もある\n
  • #22 \n
  • #23 \n
  • #24 \n
  • #25 \n
  • #26 \n
  • #27 \n
  • #28 \n
  • #29 \n
  • #30 \n
  • #31 \n
  • #32 \n
  • #33 \n
  • #34 \n
  • #35 \n
  • #36 \n
  • #37 \n