0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Gitでdevelopブランチをstagingブランチへマージする方法

0
Posted at

Gitでdevelopブランチをstagingブランチへマージする方法

チーム開発では、developブランチの変更をstagingブランチへ反映させる場面がよくあります。

今回は、developブランチをstagingブランチへマージする基本的な手順を紹介します。

今回の前提

以下のようなブランチ構成を想定します。

main
  ↑
staging
  ↑
develop

developの最新の変更をstagingへ取り込みたい場合です。

1. stagingブランチへ移動する

まずはマージ先のブランチへ移動します。

git switch staging

2. リモートの最新状態を取得する

最新の状態で作業するために、リモートの変更を取り込みます。

git pull origin staging

3. developをマージする

developブランチをマージします。

git merge develop

コンフリクトが発生しなければ、この時点でマージは完了です。

4. リモートへ反映する

最後にリモートへプッシュします。

git push origin staging

コンフリクトが発生した場合

コンフリクトが発生した場合は、対象ファイルを修正した後に以下を実行します。

git add .
git commit

その後、リモートへ反映します。

git push origin staging

リモートのdevelopを直接マージする方法

ローカルのdevelopが最新かわからない場合は、リモートブランチを直接指定することもできます。

git fetch origin
git merge origin/develop

これなら、最新のorigin/developをマージできます。

よくあるミス

developブランチ上でgit merge stagingを実行する

マージする向きが逆になります。

現在いるブランチに対して、指定したブランチが取り込まれるため、

git switch staging
git merge develop

の順番で実行することが重要です。

まとめ

developstagingへマージする基本的な流れは以下の4ステップです。

git switch staging
git pull origin staging
git merge develop
git push origin staging

チーム開発では頻繁に行う操作なので、どちらのブランチにいるかをgit statusgit branchで確認してからマージする習慣を付けると、誤操作を防ぎやすくなります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?