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?

More than 1 year has passed since last update.

Github ブランチとマージ

Last updated at Posted at 2024-01-28

使用するリモートリポジトリ:New-repository
現在こんな感じで、ブランチはありません。
スクリーンショット 2024-01-28 9.22.10.png

ブランチ作成

ローカルリポジトリはHelloworld
現在ローカルにあるブランチは以下の通り。
featureをリモートリポジトリに紐つける。

# ローカルのfeatureブランチを、リモートリポジトリ(origin)に追加
git push -u origin feature

スクリーンショット 2024-01-28 9.46.40.png
増えてる!! 今追加したfeatureブランチをクリック
スクリーンショット 2024-01-28 9.47.57.png
mainブランチには以下のファイル1つだけ。
スクリーンショット 2024-01-28 9.49.33.png
featureブランチには複数のファイルが保存されています。
スクリーンショット 2024-01-28 9.50.31.png

マージする

例えば、
featureブランチの変更をmainブランチにマージする場合

  1. git checkoutコマンドでmainブランチに切り替え
  2. git mergeコマンドにfeatureブランチを指定して実行
    マージ先に移動して、マージ元をコマンドで指定する。
# ブランチ先に移動
git checkout ブランチ先

#マージ元を指名
git merge マージ元のブランチ名

マージ完了。以下に表示されている4つのファイルをマージします。この時点ではローカルリポジトリ内でマージしただけなので、リモートには反映されていません!
スクリーンショット 2024-01-28 10.26.20.png
指定したブランチのファイル一覧を表示

git ls-tree --name-only ブランチ名

表示されています。
スクリーンショット 2024-01-28 10.29.17.png
最後にこれらのマージをリモートリポジトリにPUSH

git push origin main 

スクリーンショット 2024-01-28 10.33.19.png
OK!!!

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?