git flow ブランチモデルの各ブランチの役割とコマンドによる初期化

プログラムなどのバージョン管理を行える、無料ソースコード管理 (SCM: software configuration management) ソフト Git で用いられるブランチモデルのひとつである git flow各ブランチの役割を簡単に説明します。
git flow ブランチモデルの Git リポジトリを初期化する手順と、ログによるコミット履歴の確認結果も紹介します。

git-scm 公式サイトの一部 20250408

Git-2.49.0 (64 bit) を使用します。

git flow ブランチモデルとは?

git flow は、Vincent Driessen 氏が 2010 年に提唱した git のブランチモデルです。

This model was conceived in 2010, now more than 10 years ago, and not very long after Git itself came into being. In those 10 years, git-flow (the branching model laid out in this article) has become hugely popular in many a software team to the point where people have started treating it like a standard of sorts — but unfortunately also as a dogma or panacea.

このモデルは 2010 年に考案されました。今から 10 年以上前であり、Git 自体が誕生してからそれほど時間が経っていません。この 10 年間で、git-flow (この記事で説明した分岐モデル) は多くのソフトウェア チームで非常に人気があり、人々はそれをある種の標準のように扱い始めましたが、残念ながら定説または万能薬としても扱われ始めました。

A successful Git branching model » nvie.com と Google 翻訳

master, develop ブランチ

git flow ブランチモデルでは、 master と develop という2つのブランチ永続的に存在します。

At the core, the development model is greatly inspired by existing models out there. The central repo holds two main branches with an infinite lifetime:

開発モデルの中核は、既存のモデルから大きくインスピレーションを得ています。中央リポジトリには、存続期間が無限である 2 つのメイン ブランチが保持されます。

  • master
  • develop
A successful Git branching model » nvie.com と Google 翻訳

master ブランチは、本番環境用(納品、リリースなど)に対応するブランチで、安定版のコミットが保持されます。
タグとして利用します。

We consider origin/master to be the main branch where the source code of HEAD always reflects a production-ready state.

オリジン/マスターは、HEAD のソース コードが常に運用準備完了状態を反映するメイン ブランチであると考えられます。

A successful Git branching model » nvie.com と Google 翻訳

develop ブランチは、次のリリースに向けて、開発された新機能や修正を統合するブランチです。
後述する feature ブランチで作られた機能が develop ブランチにマージされます。

We consider origin/develop to be the main branch where the source code of HEAD always reflects a state with the latest delivered development changes for the next release. Some would call this the “integration branch”. This is where any automatic nightly builds are built from.

私たちは、origin/develop を、HEAD のソース コードが次のリリースに向けて提供された最新の開発変更を含む状態を常に反映するメイン ブランチであると考えています。これを「統合ブランチ」と呼ぶ人もいます。ここからナイトリーの自動ビルドが構築されます。

A successful Git branching model » nvie.com と Google 翻訳 (夜間→ナイトリー)

develop ブランチの内容が安定してリリースの準備が整うと、本番環境用の master ブランチへのマージが行われます。
master ブランチにマージする前段階として、後述する release ブランチ内で調整を重ねます。
※ master ブランチのコミットにはバージョンなどを表すタグをつける場合もありますが、必須ではありません。

develop →(マージ)→ release/xxx(マージ)→ master(tag xxx)

When the source code in the develop branch reaches a stable point and is ready to be released, all of the changes should be merged back into master somehow and then tagged with a release number. How this is done in detail will be discussed further on.

開発ブランチのソース コードが安定点に達し、リリースの準備ができたら、すべての変更を何らかの方法でマスターにマージし、リリース番号のタグを付ける必要があります。これがどのように行われるかについては、後で詳しく説明します。

A successful Git branching model » nvie.com と Google 翻訳

一時的なブランチ

master, develop ブランチに、マージするための一時的なブランチには以下があります。
※一時的なブランチですが、削除しない場合もあります。

  • Feature ブランチ
    develop ブランチにマージする前の機能を開発するブランチです。
  • Release ブランチ
    本番環境用(リリース、納品など)のコミットだけを置く master ブランチに置くための準備を行うブランチです。
  • Hotfix ブランチ
    master ブランチで公開している製品のバグを修正するために作られるブランチです。

Next to the main branches master and develop, our development model uses a variety of supporting branches to aid parallel development between team members, ease tracking of features, prepare for production releases and to assist in quickly fixing live production problems. Unlike the main branches, these branches always have a limited life time, since they will be removed eventually.

マスターと開発の主要なブランチの次に、開発モデルではさまざまなサポート ブランチを使用して、チーム メンバー間の並行開発を支援し、機能の追跡を容易にし、製品リリースの準備をし、実際の製品の問題を迅速に修正するのを支援します。メイン ブランチとは異なり、これらのブランチは最終的には削除されるため、存続期間は常に限られています。

The different types of branches we may use are:

  • Feature branches
  • Release branches
  • Hotfix branches
A successful Git branching model » nvie.com と Google 翻訳

以下は、提案者のサイトを引用した各ブランチの説明です。

Feature ブランチ

feature ブランチは、新機能を開発するために一時的に作られるブランチです。
完成・中止に関わらず、新機能の開発が終了した時点で Feature ブランチは削除されます。
develop ブランチから派生します。

「feature/開発中の機能名」の形式でブランチ名を設定します。

May branch off from:
develop
Must merge back into:
develop

Feature branches (or sometimes called topic branches) are used to develop new features for the upcoming or a distant future release. When starting development of a feature, the target release in which this feature will be incorporated may well be unknown at that point. The essence of a feature branch is that it exists as long as the feature is in development, but will eventually be merged back into develop (to definitely add the new feature to the upcoming release) or discarded (in case of a disappointing experiment).

Feature branches typically exist in developer repos only, not in origin.

機能ブランチ (またはトピック ブランチと呼ばれることもあります) は、今後のリリースまたは遠い将来のリリースに向けた新機能を開発するために使用されます。機能の開発を開始するとき、その時点では、この機能が組み込まれるターゲット リリースが不明である可能性があります。フィーチャー ブランチの本質は、フィーチャーが開発中である限り存在しますが、最終的には (次のリリースに新しいフィーチャーを確実に追加するために) 開発にマージされたり、(実験が失敗した場合に) 破棄されたりすることです。

通常、機能ブランチは開発者リポジトリにのみ存在し、オリジンには存在しません。

A successful Git branching model » nvie.com と Google 翻訳

Release ブランチ

Release ブランチは、リリース用に整えるためのブランチです。
develop ブランチから派生します。

「release/バージョン名」の形式でブランチ名を設定します。
このバージョン名は master ブランチのマージした結果につけるタグと同じにする場合もあります。

May branch off from:
develop
Must merge back into:
develop and master

Release branches support preparation of a new production release. They allow for last-minute dotting of i’s and crossing t’s. Furthermore, they allow for minor bug fixes and preparing meta-data for a release (version number, build dates, etc.). By doing all of this work on a release branch, the develop branch is cleared to receive features for the next big release.

リリース ブランチは、新しい製品リリースの準備をサポートします。土壇場で i を点線したり、t を交差させたりすることができます。さらに、マイナーなバグ修正や、リリース用のメタデータ (バージョン番号、ビルド日など) の準備が可能になります。このすべての作業をリリース ブランチで実行すると、開発ブランチは次の大きなリリースの機能を受け取ることができるようになります。

A successful Git branching model » nvie.com と Google 翻訳

HotFix ブランチ

本番環境用の master ブランチで発生した重大なバグをすぐに修正するためのブランチです。
master ブランチから派生します。

「hotfix/対処したバグを指すIDやメッセージ」の形式でブランチ名を設定します。

May branch off from:master
Must merge back into:develop and master

Hotfix branches are very much like release branches in that they are also meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version. When a critical bug in a production version must be resolved immediately, a hotfix branch may be branched off from the corresponding tag on the master branch that marks the production version.

ホットフィックス ブランチは、計画外であっても新しい運用リリースの準備をすることを目的としているという点で、リリース ブランチとよく似ています。これらは、ライブ製品バージョンの望ましくない状態に即座に対処する必要性から生じます。製品版の重大なバグを直ちに解決する必要がある場合、製品版をマークするマスター ブランチ上の対応するタグからホットフィックス ブランチが分岐することがあります。

A successful Git branching model » nvie.com と Google 翻訳

git flow ブランチモデルのリポジトリの初期化

git flow ブランチモデルのリポジトリは、 git flow init コマンドで作成できます。

リポジトリを作成する空のフォルダを作業ディレクトリとしてコマンドプロンプト起動します。

Windows 10 の場合は、そのフォルダを開いたエクスプローラアドレスバーに cmd⏎ と入力するとそのフォルダを作業ディレクトリにしてコマンドプロンプトを開けます。

Git flow init によるリポジトリの初期化1
git flow init

コマンドを入力すると、前述した各ブランチ名を尋ねられます。
デフォルトの master, develop などで良い場合は、各ブランチ名の質問にエンターキー入力します。

※ハイライトしている 4 ~ 5、8 ~ 14 行目は、 Enter キーを入力しました。

Git flow init によるリポジトリの初期化2
G:\Dev\StudyTortoiseGit\GitFlow\RepoGitFlow1>git flow init
Initialized empty Git repository in G:/Dev/StudyTortoiseGit/GitFlow/RepoGitFlow1/.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/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
Hooks and filters directory? [G:/Dev/StudyTortoiseGit/GitFlow/RepoGitFlow1/.git/hooks]

.git フォルダが作成されました。
このフォルダをエクスプローラで右クリックして表示されるメニュー「TortoiseGit」→「ログを表示」を選択して、コミットの履歴を確認してみましょう。

Git flow init によるリポジトリの初期化3

develop, master 各ブランチに Inital commit というメッセージコミットが行われています。

Git flow init によるリポジトリの初期化4

git log –oneline コマンドでも同様に確認できました。

G:\Dev\StudyTortoiseGit\GitFlow\RepoGitFlow1>git log --oneline
6b93ede (HEAD -> develop, master) Initial commit

git branch コマンドでは、存在するブランチを確認できます。
* が先頭についているブランチが現在のコミットがあるブランチです。

G:\Dev\StudyTortoiseGit\GitFlow\RepoGitFlow1>git branch
* develop
  master

まとめ

今回は、プログラムなどのバージョン管理を行える、無料ソースコード管理 (SCM: software configuration management) ソフト Git で用いられるブランチモデルのひとつである git flow各ブランチの役割を簡単に説明しました。
git flow ブランチモデルの Git リポジトリを初期化する手順と、ログによるコミット履歴の確認結果も紹介しました。

参照サイト Thank You!

記事一覧 → Compota-Soft-Press

コメント

Ads Blocker Image Powered by Code Help Pro

お願い - Ads Blocker Detected

このサイトは広告を掲載して運営しています。

ポップアップを閉じて閲覧できますが、よろしければ

このサイト内の広告を非表示にする拡張機能をオフにしていただけませんか?

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

タイトルとURLをコピーしました