1
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?

More than 3 years have passed since last update.

[GitHub] ブランチ(branch)

Last updated at Posted at 2021-10-15

ブランチ(branch)とは

作業を分岐させて履歴の流れを記録していくもの。
分岐したブランチは他のブランチの影響を受けないため、同じリポジトリ内で複数の変更を同時に進めることができる。

ブランチのメリット

ブランチのメリットは以下が挙げられる。
■ プロジェクト本体に影響を与えずに作業ができる。
■ ブランチを切ることで目的別に同時並行で作業ができる。
■ 不具合が発生した場合の対応が容易にできる。

ブランチの操作

ブランチを操作するためのコマンドを紹介する。

■ ブランチを作成

ブランチはbranchコマンドで作成する。

git branch <ブランチ名>

また、ブランチの一覧を確認する場合は引数を指定せず実行する。

■ ブランチの切り替え

作成したブランチ間を移動する場合、checkoutコマンドを使用する。

git checkout <ブランチ名>

checkoutコマンドに「-b」のオプションを指定すると、ブランチの作成と切り替えがまとめて行える。

■ ブランチのマージ

マージとは、現在のブランチに他のブランチの変更を統合させることで、mergeコマンドを使用する。

git merge <ブランチ名>

■ ブランチの削除

不要になったブランチを削除する場合は、「-d」オプションを指定する。

git branch -d <ブランチ名>

まとめ

ブランチについて、メリットやコマンドについてまとめた。
次は、Gitのブランチモデル「git-flow」について学んでいきたい。

1
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
1
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?