<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>チーム開発 - CayTech Lab</title>
	<atom:link href="https://caymezon.com/tag/%e3%83%81%e3%83%bc%e3%83%a0%e9%96%8b%e7%99%ba/feed/" rel="self" type="application/rss+xml" />
	<link>https://caymezon.com</link>
	<description></description>
	<lastBuildDate>Sat, 07 Feb 2026 09:57:42 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.5</generator>

<image>
	<url>https://caymezon.com/wp-content/uploads/2026/01/cropped-CayTechLab-32x32.jpg</url>
	<title>チーム開発 - CayTech Lab</title>
	<link>https://caymezon.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<atom:link rel='hub' href='https://caymezon.com/?pushpress=hub'/>
	<item>
		<title>【保存版】Git実務ガイド｜ブランチ戦略から失敗時のリカバリまで完全網羅</title>
		<link>https://caymezon.com/git-branch-strategy-complete-guide/</link>
					<comments>https://caymezon.com/git-branch-strategy-complete-guide/#respond</comments>
		
		<dc:creator><![CDATA[caymezon]]></dc:creator>
		<pubDate>Mon, 12 Jan 2026 08:37:29 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[チーム開発]]></category>
		<category><![CDATA[トラブルシューティング]]></category>
		<category><![CDATA[バージョン管理]]></category>
		<category><![CDATA[ブランチ戦略]]></category>
		<guid isPermaLink="false">https://caymezon.com/git-branch-strategy-complete-guide/</guid>

					<description><![CDATA[<p>目次 はじめにブランチ戦略の基本なぜブランチを分けるのかGit Flow：最も一般的なブランチ戦略各ブランチの役割基本操作ブランチの作成と切り替えコミットプッシュマージ日常的な運用フローパターン1：新機能を開発パターン2 [&#8230;]</p>
<p>The post <a href="https://caymezon.com/git-branch-strategy-complete-guide/">【保存版】Git実務ガイド｜ブランチ戦略から失敗時のリカバリまで完全網羅</a> first appeared on <a href="https://caymezon.com">CayTech Lab</a>.</p>]]></description>
										<content:encoded><![CDATA[<div id="toc" class="toc tnt-number toc-center tnt-number border-element"><input type="checkbox" class="toc-checkbox" id="toc-checkbox-2" checked><label class="toc-title" for="toc-checkbox-2">目次</label>
    <div class="toc-content">
    <ol class="toc-list open"><li><a href="#toc1" tabindex="0">はじめに</a></li><li><a href="#toc2" tabindex="0">ブランチ戦略の基本</a><ol><li><a href="#toc3" tabindex="0">なぜブランチを分けるのか</a></li><li><a href="#toc4" tabindex="0">Git Flow：最も一般的なブランチ戦略</a></li><li><a href="#toc5" tabindex="0">各ブランチの役割</a></li></ol></li><li><a href="#toc6" tabindex="0">基本操作</a><ol><li><a href="#toc7" tabindex="0">ブランチの作成と切り替え</a></li><li><a href="#toc8" tabindex="0">コミット</a></li><li><a href="#toc9" tabindex="0">プッシュ</a></li><li><a href="#toc10" tabindex="0">マージ</a></li></ol></li><li><a href="#toc11" tabindex="0">日常的な運用フロー</a><ol><li><a href="#toc12" tabindex="0">パターン1：新機能を開発</a></li><li><a href="#toc13" tabindex="0">パターン2：複数の機能を並行開発</a></li><li><a href="#toc14" tabindex="0">パターン3：mainへのリリース</a></li></ol></li><li><a href="#toc15" tabindex="0">よくある失敗とリカバリ</a><ol><li><a href="#toc16" tabindex="0">失敗1：mainで誤って作業してしまった</a></li><li><a href="#toc17" tabindex="0">失敗2：developとmainがずれてしまった</a></li><li><a href="#toc18" tabindex="0">失敗3：コミットメッセージを間違えた</a></li><li><a href="#toc19" tabindex="0">失敗4：間違ったファイルをコミットしてしまった</a></li><li><a href="#toc20" tabindex="0">失敗5：コンフリクトが発生した</a></li></ol></li><li><a href="#toc21" tabindex="0">便利なコマンド</a><ol><li><a href="#toc22" tabindex="0">空コミット</a></li><li><a href="#toc23" tabindex="0">特定のコミットを別ブランチに適用</a></li><li><a href="#toc24" tabindex="0">コミット履歴を確認</a></li><li><a href="#toc25" tabindex="0">変更内容を確認</a></li><li><a href="#toc26" tabindex="0">変更を一時保存</a></li><li><a href="#toc27" tabindex="0">ブランチを削除</a></li></ol></li><li><a href="#toc28" tabindex="0">GitHub連携</a><ol><li><a href="#toc29" tabindex="0">Re-run jobs（GitHub Actions）</a></li><li><a href="#toc30" tabindex="0">Pull Request（PR）</a></li></ol></li><li><a href="#toc31" tabindex="0">ベストプラクティス</a><ol><li><a href="#toc32" tabindex="0">1. 作業前に必ずブランチ確認</a></li><li><a href="#toc33" tabindex="0">2. 小まめにコミット</a></li><li><a href="#toc34" tabindex="0">3. 定期的にdevelopを更新</a></li><li><a href="#toc35" tabindex="0">4. 意味のあるコミットメッセージ</a></li><li><a href="#toc36" tabindex="0">5. mainとdevelopを保護</a></li></ol></li><li><a href="#toc37" tabindex="0">チートシート</a><ol><li><a href="#toc38" tabindex="0">ブランチ操作</a></li><li><a href="#toc39" tabindex="0">コミット操作</a></li><li><a href="#toc40" tabindex="0">リモート操作</a></li><li><a href="#toc41" tabindex="0">マージ操作</a></li><li><a href="#toc42" tabindex="0">確認系</a></li><li><a href="#toc43" tabindex="0">リカバリ系</a></li></ol></li><li><a href="#toc44" tabindex="0">まとめ</a><ol><li><a href="#toc45" tabindex="0">ブランチ戦略</a></li><li><a href="#toc46" tabindex="0">基本フロー</a></li><li><a href="#toc47" tabindex="0">失敗時の対処</a></li><li><a href="#toc48" tabindex="0">覚えておくべきコマンド</a></li></ol></li><li><a href="#toc49" tabindex="0">おわりに</a></li><li><a href="#toc50" tabindex="0">参考リンク</a></li></ol>
    </div>
  </div>

<h2><span id="toc1">はじめに</span></h2>
<p>Gitは強力なバージョン管理ツールですが、<strong>使い方を間違えると大変なことになります。</strong></p>
<p>この記事では、実務で使える<strong>ブランチ戦略から、よくある失敗とそのリカバリ方法</strong>まで、完全網羅します。</p>
<p><strong>対象読者：</strong></p>
<ul>
<li>Gitの基本は分かるが、実務での使い方に不安がある方</li>
<li>ブランチ戦略を学びたい方</li>
<li>失敗したときの対処法を知りたい方</li>
<li>チーム開発でGitを使う予定の方</li>
</ul>
<p><strong>この記事で分かること：</strong></p>
<ul>
<li>main/develop/feature/* の使い分け</li>
<li>日常的な操作フロー</li>
<li>失敗したときのリカバリ方法</li>
<li>便利なコマンド集</li>
</ul>
<hr>
<p><!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"独習Git","b":"翔泳社","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/51IvJi4w3iL._SL500_.jpg","\/51LnCnusa1L._SL500_.jpg","\/41xsL1rvEPL._SL500_.jpg","\/41hx9HEeh8L._SL500_.jpg","\/41H67n8S3gL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/4798144614","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/4798144614","a_id":1384942,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E7%8B%AC%E7%BF%92Git\/","a_id":1384917,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2},{"id":3,"u_tx":"Yahoo!ショッピングで見る","u_bc":"#66a7ff","u_url":"https:\/\/shopping.yahoo.co.jp\/search?first=1\u0026p=%E7%8B%AC%E7%BF%92Git","a_id":1466950,"p_id":1225,"pl_id":27061,"pc_id":1925,"s_n":"yahoo","u_so":3}],"eid":"Ifo9s","s":"s"});</script></p>
<div id="msmaflink-Ifo9s">リンク</div>
<p><!-- MoshimoAffiliateEasyLink END --></p>
<h2><span id="toc2">ブランチ戦略の基本</span></h2>
<h3><span id="toc3">なぜブランチを分けるのか</span></h3>
<p><strong>1つのブランチだけだと：</strong></p>
<pre><code class="language-plaintext">main
  ├─ 機能Aを開発中
  ├─ 機能Bを開発中
  └─ バグ修正中

→ すべてが混ざって混乱</code></pre>
<p><strong>ブランチを分けると：</strong></p>
<pre><code class="language-plaintext">main（本番）
  ├─ develop（開発）
  │   ├─ feature/機能A
  │   ├─ feature/機能B
  │   └─ fix/バグ修正
  └─ hotfix/緊急修正</code></pre>
<p><strong>それぞれ独立して作業できる！</strong></p>
<hr>
<h3><span id="toc4">Git Flow：最も一般的なブランチ戦略</span></h3>
<pre><code class="language-plaintext">main（本番環境）
  ├─ 常に安定版
  └─ リリース済みのコード

develop（開発環境）
  ├─ 開発中のコード
  └─ すべての作業の起点

feature/*（機能開発）
  ├─ feature/login
  ├─ feature/payment
  └─ 開発完了後、developにマージ

hotfix/*（緊急修正）
  ├─ hotfix/critical-bug
  └─ 本番の緊急バグ修正</code></pre>
<hr>
<h3><span id="toc5">各ブランチの役割</span></h3>
<h4>mainブランチ</h4>
<p><strong>役割：</strong></p>
<ul>
<li>本番環境のコード</li>
<li>常に動作する状態</li>
<li>リリース済みの確定版</li>
</ul>
<p><strong>ルール：</strong></p>
<ul>
<li>❌ 直接編集しない</li>
<li>✅ developまたはhotfixからマージのみ</li>
<li>✅ タグでバージョン管理</li>
</ul>
<p><strong>例：</strong></p>
<pre><code class="language-plaintext">main
  ├─ v1.0.0
  ├─ v1.1.0
  └─ v2.0.0</code></pre>
<hr>
<h4>developブランチ</h4>
<p><strong>役割：</strong></p>
<ul>
<li>開発環境のコード</li>
<li>すべての機能開発の起点</li>
<li>次のリリース候補</li>
</ul>
<p><strong>ルール：</strong></p>
<ul>
<li>✅ feature/* からマージを受け入れる</li>
<li>✅ テスト済みの機能のみマージ</li>
<li>✅ mainより先に進んでいる</li>
</ul>
<p><strong>イメージ：</strong></p>
<pre><code class="language-plaintext">develop = main + 開発中の機能</code></pre>
<hr>
<h4>feature/* ブランチ</h4>
<p><strong>役割：</strong></p>
<ul>
<li>個別の機能開発</li>
<li>独立して作業できる</li>
<li>開発完了後、developにマージ</li>
</ul>
<p><strong>命名規則：</strong></p>
<pre><code class="language-plaintext">feature/ログイン機能
feature/決済機能
feature/ユーザー管理</code></pre>
<p><strong>ライフサイクル：</strong></p>
<pre><code class="language-plaintext">1. developから作成
2. 機能開発
3. developにマージ
4. ブランチ削除</code></pre>
<hr>
<h4>hotfix/* ブランチ</h4>
<p><strong>役割：</strong></p>
<ul>
<li>本番の緊急バグ修正</li>
<li>mainから直接作成</li>
<li>mainとdevelopの両方にマージ</li>
</ul>
<p><strong>使用タイミング：</strong></p>
<pre><code class="language-plaintext">本番でバグ発見
  ↓ 緊急修正が必要
hotfix/critical-bug を作成
  ↓ 修正
mainにマージ（本番反映）
  ↓ 同時に
developにもマージ（開発環境にも反映）</code></pre>
<hr>
<h2><span id="toc6">基本操作</span></h2>
<h3><span id="toc7">ブランチの作成と切り替え</span></h3>
<h4>新しいブランチを作成して切り替え</h4>
<pre><code class="language-bash">git checkout develop
git checkout -b feature/new-function

# または
git switch -c feature/new-function</code></pre>
<p><strong>説明：</strong></p>
<ul>
<li><code>-b</code> オプションで作成と切り替えを同時に実行</li>
<li><code>switch</code> は新しいGitコマンド（v2.23以降）</li>
</ul>
<hr>
<h4>既存のブランチに切り替え</h4>
<pre><code class="language-bash"># developに切り替え
git checkout develop

# mainに切り替え
git checkout main</code></pre>
<hr>
<h4>ブランチ一覧を確認</h4>
<pre><code class="language-bash"># ローカルブランチ一覧
git branch

# 出力例：
  main
* develop  ← *が現在のブランチ
  feature/login

# リモートブランチも含めて表示
git branch -a

# 出力例：
* develop
  main
  remotes/origin/develop
  remotes/origin/main
  remotes/origin/feature/login</code></pre>
<hr>
<h3><span id="toc8">コミット</span></h3>
<h4>ステージングとコミット</h4>
<pre><code class="language-bash"># ファイルをステージング
git add file.txt

# すべてのファイルをステージング
git add .

# コミット
git commit -m "feat: ログイン機能を追加"</code></pre>
<hr>
<h4>コミットメッセージの規約</h4>
<p><strong>Conventional Commits:</strong></p>
<pre><code class="language-plaintext"><type>: <description>

type:
- feat: 新機能
- fix: バグ修正
- docs: ドキュメント
- style: コードスタイル
- refactor: リファクタリング
- test: テスト
- chore: その他</code></pre>
<p><strong>例：</strong></p>
<pre><code class="language-bash">git commit -m "feat: ユーザー登録機能を追加"
git commit -m "fix: ログインエラーを修正"
git commit -m "docs: READMEを更新"</code></pre>
<hr>
<h3><span id="toc9">プッシュ</span></h3>
<h4>リモートにプッシュ</h4>
<pre><code class="language-bash"># 現在のブランチをリモートにプッシュ
git push origin feature/login

# 初回プッシュ時（追跡ブランチを設定）
git push -u origin feature/login

# 次回以降
git push</code></pre>
<p><strong><code>-u</code> オプション：</strong></p>
<ul>
<li>upstream（追跡ブランチ）を設定</li>
<li>次回以降は <code>git push</code> だけでOK</li>
</ul>
<hr>
<h3><span id="toc10">マージ</span></h3>
<h4>developにマージ</h4>
<pre><code class="language-bash"># developに切り替え
git checkout develop

# featureブランチをマージ
git merge feature/login

# 出力例：
Updating abc1234..def5678
Fast-forward
 login.js | 50 +++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

# リモートにプッシュ
git push origin develop</code></pre>
<hr>
<h4>mainにマージ</h4>
<pre><code class="language-bash"># mainに切り替え
git checkout main

# developをマージ
git merge develop

# プッシュ
git push origin main</code></pre>
<hr>
<h2><span id="toc11">日常的な運用フロー</span></h2>
<h3><span id="toc12">パターン1：新機能を開発</span></h3>
<h4>Step 1：featureブランチを作成</h4>
<pre><code class="language-bash"># developから作成
git checkout develop
git pull origin develop  # 最新の状態に更新

# featureブランチ作成
git checkout -b feature/user-profile</code></pre>
<hr>
<h4>Step 2：開発作業</h4>
<pre><code class="language-bash"># ファイルを編集
code user-profile.js

# コミット（何度でも）
git add user-profile.js
git commit -m "feat: ユーザープロフィール表示機能"

git add user-profile.css
git commit -m "style: プロフィール画面のスタイル調整"

git add tests/user-profile.test.js
git commit -m "test: ユーザープロフィールのテスト追加"</code></pre>
<hr>
<h4>Step 3：リモートにプッシュ</h4>
<pre><code class="language-bash"># 初回
git push -u origin feature/user-profile

# 2回目以降
git push</code></pre>
<hr>
<h4>Step 4：developにマージ</h4>
<pre><code class="language-bash"># developに切り替え
git checkout develop

# 最新の状態に更新
git pull origin develop

# featureブランチをマージ
git merge feature/user-profile

# コンフリクトがなければ
git push origin develop

# featureブランチを削除（オプション）
git branch -d feature/user-profile
git push origin --delete feature/user-profile</code></pre>
<hr>
<h3><span id="toc13">パターン2：複数の機能を並行開発</span></h3>
<pre><code class="language-bash"># 機能A開発
git checkout develop
git checkout -b feature/function-a
# 開発...
git push origin feature/function-a

# 機能Bも開発したい
git checkout develop  # developに戻る
git checkout -b feature/function-b
# 開発...
git push origin feature/function-b

# 機能Aに戻る
git checkout feature/function-a
# 開発続き...</code></pre>
<p><strong>ポイント：</strong></p>
<ul>
<li>各機能が独立して開発できる</li>
<li>いつでもブランチを切り替えられる</li>
</ul>
<hr>
<h3><span id="toc14">パターン3：mainへのリリース</span></h3>
<pre><code class="language-bash"># developの作業が完了
git checkout main
git pull origin main

# developをマージ
git merge develop

# タグを付ける
git tag -a v1.0.0 -m "バージョン1.0.0リリース"

# プッシュ
git push origin main
git push origin v1.0.0</code></pre>
<hr>
<h2><span id="toc15">よくある失敗とリカバリ</span></h2>
<h3><span id="toc16">失敗1：mainで誤って作業してしまった</span></h3>
<h4>状況</h4>
<pre><code class="language-bash"># mainブランチにいることに気づかず作業
git add file.txt
git commit -m "機能追加"

# あっ、mainだった！
git branch
# * main  ← まずい！</code></pre>
<hr>
<h4>リカバリ方法A：まだプッシュしていない場合</h4>
<pre><code class="language-bash"># コミットを取り消し（変更は残る）
git reset --soft HEAD~1

# developに切り替え
git checkout develop

# 再度コミット
git add file.txt
git commit -m "機能追加"
git push origin develop</code></pre>
<p><strong><code>reset --soft</code>：</strong></p>
<ul>
<li>コミットだけ取り消し</li>
<li>ファイルの変更は残る</li>
<li>ステージング状態も残る</li>
</ul>
<hr>
<h4>リカバリ方法B：すでにプッシュしてしまった場合</h4>
<pre><code class="language-bash"># developに該当のコミットを持っていく
git checkout develop
git cherry-pick コミットハッシュ
git push origin develop

# mainから削除
git checkout main
git revert コミットハッシュ
git push origin main</code></pre>
<p><strong><code>cherry-pick</code>：</strong></p>
<ul>
<li>特定のコミットだけを別ブランチに適用</li>
</ul>
<p><strong><code>revert</code>：</strong></p>
<ul>
<li>コミットを打ち消す新しいコミットを作成</li>
<li>履歴は残る（安全）</li>
</ul>
<hr>
<h3><span id="toc17">失敗2：developとmainがずれてしまった</span></h3>
<h4>状況</h4>
<pre><code class="language-plaintext">main: 最新の状態
develop: 古い状態

→ mainで作業してしまった
→ developに反映されていない</code></pre>
<hr>
<h4>リカバリ方法：mainの変更をdevelopにマージ</h4>
<pre><code class="language-bash"># developに切り替え
git checkout develop

# mainの変更を取り込む
git merge main

# 出力例：
Updating abc1234..def5678
Fast-forward
 file.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

# プッシュ
git push origin develop</code></pre>
<p><strong>これで同期完了！</strong></p>
<hr>
<h3><span id="toc18">失敗3：コミットメッセージを間違えた</span></h3>
<h4>まだプッシュしていない場合</h4>
<pre><code class="language-bash"># 最後のコミットメッセージを修正
git commit --amend -m "正しいメッセージ"</code></pre>
<hr>
<h4>すでにプッシュしてしまった場合</h4>
<pre><code class="language-bash"># 修正
git commit --amend -m "正しいメッセージ"

# 強制プッシュ（注意！）
git push -f origin feature/my-branch</code></pre>
<p><strong>⚠️ 注意：</strong></p>
<ul>
<li><code>git push -f</code> は履歴を書き換える</li>
<li>チーム開発では使わない（他の人の作業が壊れる）</li>
<li>自分専用のブランチでのみ使用</li>
</ul>
<hr>
<h3><span id="toc19">失敗4：間違ったファイルをコミットしてしまった</span></h3>
<h4>まだプッシュしていない場合</h4>
<pre><code class="language-bash"># 最後のコミットを取り消し（変更は残る）
git reset --soft HEAD~1

# 正しいファイルだけをステージング
git add correct-file.txt
git commit -m "メッセージ"

# 間違ったファイルは破棄
git checkout -- wrong-file.txt</code></pre>
<hr>
<h4>すでにプッシュしてしまった場合</h4>
<pre><code class="language-bash"># ファイルを削除するコミット
git rm wrong-file.txt
git commit -m "不要なファイルを削除"
git push origin feature/my-branch</code></pre>
<hr>
<h3><span id="toc20">失敗5：コンフリクトが発生した</span></h3>
<h4>状況</h4>
<pre><code class="language-bash">git merge feature/function-a

# 出力：
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.</code></pre>
<hr>
<h4>解決手順</h4>
<p><strong>1. コンフリクトしているファイルを確認：</strong></p>
<pre><code class="language-bash">git status

# 出力：
Unmerged paths:
  both modified:   file.txt</code></pre>
<hr>
<p><strong>2. ファイルを開いて編集：</strong></p>
<pre><code class="language-plaintext"><<<<<<< HEAD
現在のブランチの内容
=======
マージしようとしているブランチの内容
>>>>>>> feature/function-a</code></pre>
<p><strong>どちらを採用するか決める：</strong></p>
<pre><code class="language-plaintext"># 最終的な内容（コンフリクトマーカーを削除）
採用する内容</code></pre>
<hr>
<p><strong>3. コミット：</strong></p>
<pre><code class="language-bash">git add file.txt
git commit -m "merge: コンフリクトを解決"</code></pre>
<hr>
<h2><span id="toc21">便利なコマンド</span></h2>
<h3><span id="toc22">空コミット</span></h3>
<p><strong>ファイルを変更せずにコミット：</strong></p>
<pre><code class="language-bash">git commit --allow-empty -m "chore: CI/CDをトリガー"</code></pre>
<p><strong>使用例：</strong></p>
<ul>
<li>CI/CDを再実行したい</li>
<li>Git履歴に記録を残したい</li>
<li>ファイル変更なしでプッシュしたい</li>
</ul>
<hr>
<h3><span id="toc23">特定のコミットを別ブランチに適用</span></h3>
<pre><code class="language-bash"># コミットハッシュを確認
git log --oneline

# 出力例：
abc1234 feat: 機能追加
def5678 fix: バグ修正

# 別ブランチに切り替え
git checkout target-branch

# 特定のコミットを適用
git cherry-pick abc1234</code></pre>
<hr>
<h3><span id="toc24">コミット履歴を確認</span></h3>
<pre><code class="language-bash"># 簡易表示
git log --oneline

# グラフ表示
git log --graph --oneline --all

# 出力例：
* abc1234 (HEAD -> develop) feat: 機能追加
* def5678 (origin/develop) fix: バグ修正
* ghi9012 (main) chore: 初期設定</code></pre>
<hr>
<h3><span id="toc25">変更内容を確認</span></h3>
<pre><code class="language-bash"># まだステージングしていない変更
git diff

# ステージング済みの変更
git diff --staged

# ブランチ間の差分
git diff develop..main</code></pre>
<hr>
<h3><span id="toc26">変更を一時保存</span></h3>
<pre><code class="language-bash"># 変更を一時保存
git stash

# 別のブランチで作業...

# 変更を復元
git stash pop

# stash一覧
git stash list</code></pre>
<p><strong>使用例：</strong></p>
<ul>
<li>作業中に別のブランチに切り替える必要がある</li>
<li>コミットしたくないが、変更を保存したい</li>
</ul>
<hr>
<h3><span id="toc27">ブランチを削除</span></h3>
<pre><code class="language-bash"># ローカルブランチを削除
git branch -d feature/old-feature

# まだマージしていないブランチを強制削除
git branch -D feature/old-feature

# リモートブランチを削除
git push origin --delete feature/old-feature</code></pre>
<hr>
<h2><span id="toc28">GitHub連携</span></h2>
<p><!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"はじめてでもできる GitとGitHubの教科書","b":"SBクリエイティブ","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/510mBBi5YjL._SL500_.jpg","\/51qxfnTVWWL._SL500_.jpg","\/41Xx-cHoZIL._SL500_.jpg","\/51EhsMa7eaL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/481561539X","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/481561539X","a_id":1384942,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E3%81%AF%E3%81%98%E3%82%81%E3%81%A6%E3%81%A7%E3%82%82%E3%81%A7%E3%81%8D%E3%82%8B%20Git%E3%81%A8GitHub%E3%81%AE%E6%95%99%E7%A7%91%E6%9B%B8\/","a_id":1384917,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2},{"id":3,"u_tx":"Yahoo!ショッピングで見る","u_bc":"#66a7ff","u_url":"https:\/\/shopping.yahoo.co.jp\/search?first=1\u0026p=%E3%81%AF%E3%81%98%E3%82%81%E3%81%A6%E3%81%A7%E3%82%82%E3%81%A7%E3%81%8D%E3%82%8B%20Git%E3%81%A8GitHub%E3%81%AE%E6%95%99%E7%A7%91%E6%9B%B8","a_id":1466950,"p_id":1225,"pl_id":27061,"pc_id":1925,"s_n":"yahoo","u_so":3}],"eid":"SbOW5","s":"s"});</script></p>
<div id="msmaflink-SbOW5">リンク</div>
<p><!-- MoshimoAffiliateEasyLink END --></p>
<h3><span id="toc29">Re-run jobs（GitHub Actions）</span></h3>
<p><strong>GitHub Actions が失敗したときの再実行方法：</strong></p>
<h4>方法1：GitHub UIから再実行（推奨）</h4>
<pre><code class="language-plaintext">GitHub → Actions
→ 失敗したWorkflow
→ Re-run jobs
→ Re-run all jobs</code></pre>
<p><strong>メリット：</strong></p>
<ul>
<li>コード変更不要</li>
<li>設定変更後に使う</li>
</ul>
<hr>
<h4>方法2：空コミット</h4>
<pre><code class="language-bash">git commit --allow-empty -m "chore: GitHub Actions再実行"
git push origin main</code></pre>
<p><strong>メリット：</strong></p>
<ul>
<li>Git履歴に記録される</li>
<li>コマンドラインで完結</li>
</ul>
<hr>
<h3><span id="toc30">Pull Request（PR）</span></h3>
<p><strong>チーム開発での標準フロー：</strong></p>
<h4>Step 1：featureブランチで開発</h4>
<pre><code class="language-bash">git checkout -b feature/new-function
# 開発...
git push origin feature/new-function</code></pre>
<hr>
<h4>Step 2：GitHub でPRを作成</h4>
<pre><code class="language-plaintext">GitHub → Pull requests
→ New pull request
→ base: develop ← compare: feature/new-function
→ Create pull request</code></pre>
<hr>
<h4>Step 3：レビュー</h4>
<pre><code class="language-plaintext">チームメンバーがレビュー
→ コメント
→ 承認</code></pre>
<hr>
<h4>Step 4：マージ</h4>
<pre><code class="language-plaintext">Merge pull request
→ Confirm merge
→ Delete branch（オプション）</code></pre>
<hr>
<p><!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"GitHub CI\/CD実践ガイド――持続可能なソフトウェア開発を支えるGitHub Actionsの設計と運用 (エンジニア選書)","b":"技術評論社","t":"","d":"https:\/\/m.media-amazon.com","c_p":"\/images\/I","p":["\/51rzki71LxL._SL500_.jpg","\/41fAMNJywPL._SL500_.jpg","\/41Dy2qzIwgL._SL500_.jpg","\/31MRBqS4faL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/4297141736","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":1,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/4297141736","a_id":1384942,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"id":2,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/GitHub%20CI%2FCD%E5%AE%9F%E8%B7%B5%E3%82%AC%E3%82%A4%E3%83%89%E2%80%95%E2%80%95%E6%8C%81%E7%B6%9A%E5%8F%AF%E8%83%BD%E3%81%AA%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E9%96%8B%E7%99%BA%E3%82%92%E6%94%AF%E3%81%88%E3%82%8BGitHub%20Actions%E3%81%AE%E8%A8%AD%E8%A8%88%E3%81%A8%E9%81%8B%E7%94%A8%20(%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E9%81%B8%E6%9B%B8)\/","a_id":1384917,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":2},{"id":3,"u_tx":"Yahoo!ショッピングで見る","u_bc":"#66a7ff","u_url":"https:\/\/shopping.yahoo.co.jp\/search?first=1\u0026p=GitHub%20CI%2FCD%E5%AE%9F%E8%B7%B5%E3%82%AC%E3%82%A4%E3%83%89%E2%80%95%E2%80%95%E6%8C%81%E7%B6%9A%E5%8F%AF%E8%83%BD%E3%81%AA%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2%E9%96%8B%E7%99%BA%E3%82%92%E6%94%AF%E3%81%88%E3%82%8BGitHub%20Actions%E3%81%AE%E8%A8%AD%E8%A8%88%E3%81%A8%E9%81%8B%E7%94%A8%20(%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E9%81%B8%E6%9B%B8)","a_id":1466950,"p_id":1225,"pl_id":27061,"pc_id":1925,"s_n":"yahoo","u_so":3}],"eid":"P0azt","s":"s"});</script></p>
<div id="msmaflink-P0azt">リンク</div>
<p><!-- MoshimoAffiliateEasyLink END --></p>
<h2><span id="toc31">ベストプラクティス</span></h2>
<h3><span id="toc32">1. 作業前に必ずブランチ確認</span></h3>
<pre><code class="language-bash"># 習慣化する
git branch</code></pre>
<p><strong>または、プロンプトに表示：</strong></p>
<pre><code class="language-bash"># ~/.bashrc に追加
parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "</code></pre>
<p><strong>表示例：</strong></p>
<pre><code class="language-plaintext">~/project (develop) $</code></pre>
<hr>
<h3><span id="toc33">2. 小まめにコミット</span></h3>
<pre><code class="language-bash"># 悪い例
git add .
git commit -m "いろいろ修正"

# 良い例
git add login.js
git commit -m "feat: ログイン機能追加"

git add login.css
git commit -m "style: ログイン画面のスタイル調整"

git add tests/login.test.js
git commit -m "test: ログイン機能のテスト追加"</code></pre>
<p><strong>メリット：</strong></p>
<ul>
<li>履歴が分かりやすい</li>
<li>問題があったときに特定しやすい</li>
<li>レビューしやすい</li>
</ul>
<hr>
<h3><span id="toc34">3. 定期的にdevelopを更新</span></h3>
<pre><code class="language-bash"># 作業開始時
git checkout develop
git pull origin develop

# mainの変更も取り込む
git merge origin/main

# featureブランチでも定期的に
git checkout feature/my-feature
git merge develop  # developの最新を取り込む</code></pre>
<p><strong>メリット：</strong></p>
<ul>
<li>コンフリクトを早期に発見</li>
<li>最新の状態で開発できる</li>
</ul>
<hr>
<h3><span id="toc35">4. 意味のあるコミットメッセージ</span></h3>
<pre><code class="language-bash"># 悪い例
git commit -m "修正"
git commit -m "update"
git commit -m "fix"

# 良い例
git commit -m "feat: ユーザー登録機能を追加"
git commit -m "fix: ログインエラーを修正（#123）"
git commit -m "docs: READMEに環境構築手順を追加"</code></pre>
<hr>
<h3><span id="toc36">5. mainとdevelopを保護</span></h3>
<p><strong>GitHub設定：</strong></p>
<pre><code class="language-plaintext">Settings → Branches
→ Add branch protection rule

main:
  ✅ Require pull request reviews
  ✅ Require status checks to pass
  ❌ Allow force pushes

develop:
  ✅ Require pull request reviews
  ❌ Allow force pushes</code></pre>
<p><strong>これで：</strong></p>
<ul>
<li>誤って直接プッシュできない</li>
<li>レビューが必須</li>
<li>安全性向上</li>
</ul>
<hr>
<h2><span id="toc37">チートシート</span></h2>
<h3><span id="toc38">ブランチ操作</span></h3>
<pre><code class="language-bash"># ブランチ一覧
git branch

# ブランチ作成
git checkout -b feature/new

# ブランチ切り替え
git checkout develop

# ブランチ削除
git branch -d feature/old</code></pre>
<hr>
<h3><span id="toc39">コミット操作</span></h3>
<pre><code class="language-bash"># コミット
git add .
git commit -m "メッセージ"

# コミット修正
git commit --amend -m "修正後のメッセージ"

# コミット取り消し（変更は残る）
git reset --soft HEAD~1

# 空コミット
git commit --allow-empty -m "メッセージ"</code></pre>
<hr>
<h3><span id="toc40">リモート操作</span></h3>
<pre><code class="language-bash"># プッシュ
git push origin branch-name

# プル
git pull origin branch-name

# リモートブランチ削除
git push origin --delete branch-name</code></pre>
<hr>
<h3><span id="toc41">マージ操作</span></h3>
<pre><code class="language-bash"># マージ
git merge branch-name

# コンフリクト確認
git status

# マージ中止
git merge --abort</code></pre>
<hr>
<h3><span id="toc42">確認系</span></h3>
<pre><code class="language-bash"># 状態確認
git status

# 履歴確認
git log --oneline

# 差分確認
git diff

# ブランチ確認
git branch -a</code></pre>
<hr>
<h3><span id="toc43">リカバリ系</span></h3>
<pre><code class="language-bash"># 変更を破棄
git checkout -- file.txt

# コミット取り消し
git reset --soft HEAD~1

# コミット打ち消し
git revert コミットハッシュ

# 特定のコミットを適用
git cherry-pick コミットハッシュ</code></pre>
<hr>
<h2><span id="toc44">まとめ</span></h2>
<h3><span id="toc45">ブランチ戦略</span></h3>
<pre><code class="language-plaintext">main（本番）
  ↓ マージ
develop（開発）
  ↓ マージ
feature/*（機能開発）</code></pre>
<p><strong>ルール：</strong></p>
<ul>
<li>mainで直接作業しない</li>
<li>developですべての開発</li>
<li>featureで個別機能</li>
</ul>
<hr>
<h3><span id="toc46">基本フロー</span></h3>
<pre><code class="language-plaintext">1. featureブランチ作成
2. 開発・コミット
3. developにマージ
4. mainにマージ（リリース時）</code></pre>
<hr>
<h3><span id="toc47">失敗時の対処</span></h3>
<pre><code class="language-plaintext">mainで誤って作業
  → developにマージ

コミットミス
  → reset --soft

コンフリクト
  → 手動で解決</code></pre>
<hr>
<h3><span id="toc48">覚えておくべきコマンド</span></h3>
<pre><code class="language-bash">git branch  # ブランチ確認
git checkout -b  # ブランチ作成
git merge  # マージ
git reset --soft  # コミット取り消し
git stash  # 一時保存</code></pre>
<hr>
<h2><span id="toc49">おわりに</span></h2>
<p>Gitは最初は難しく感じるかもしれません。</p>
<p>でも、<strong>基本的な流れを理解して、失敗を恐れずに使っていけば、必ず使いこなせるようになります。</strong></p>
<p>この記事が、あなたのGit習得の助けになれば幸いです。</p>
<p><strong>Happy Coding! 🚀</strong></p>
<hr>
<h2><span id="toc50">参考リンク</span></h2>
<ul>
<li><a href="https://git-scm.com/doc">Git公式ドキュメント</a></li>
<li><a href="https://nvie.com/posts/a-successful-git-branching-model/">Git Flow</a></li>
<li><a href="https://www.conventionalcommits.org/">Conventional Commits</a></li>
<li><a href="https://docs.github.com/">GitHub Docs</a></li>
</ul>
<p><strong>最終更新：</strong> 2026-01-12</p><p>The post <a href="https://caymezon.com/git-branch-strategy-complete-guide/">【保存版】Git実務ガイド｜ブランチ戦略から失敗時のリカバリまで完全網羅</a> first appeared on <a href="https://caymezon.com">CayTech Lab</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://caymezon.com/git-branch-strategy-complete-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
