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更新手順(コマンドver)

Last updated at Posted at 2025-04-21

Git更新手順(コマンドver)

ローカルブランチを最新の状態に更新する手順です。

1. 作業ブランチを確認する。

現在どのブランチで作業しているかを確認します。

git branch

(*が付いているブランチが現在の作業ブランチです)

2. 更新元のブランチに移動する。

通常は main (旧 master) ブランチや develop ブランチなど、最新の状態を取り込みたいブランチに移動します。

git checkout <更新元branch名>

例:main ブランチに移動する場合

git checkout main

例:develop ブランチに移動する場合

git checkout develop

3. 移動できたか確認する。

移動が成功したか再度確認します。

git branch

(*が付いているブランチが更新元のブランチになっていることを確認します)

4. 更新内容を確認する。

リモートリポジトリの最新の変更を取得しますが、ローカルブランチにはまだ反映しません。

git fetch

5. 問題がなければorigin/<branch名> (リモート追跡ブランチ) と <branch名> (ローカルブランチ) を一致させる。

リモートの変更をローカルブランチに取り込みます。

git pull

例:origin/main の変更をローカルの main ブランチに取り込む場合

git pull origin main

例:origin/develop の変更をローカルの develop ブランチに取り込む場合

git pull origin develop

6. 作業ブランチに移動する。

ご自身の作業ブランチに戻ります。

git checkout <作業branch名>

例:feature/new-login ブランチで作業していた場合

git checkout feature/new-login

7. 移動できたか確認する。

作業ブランチに戻れたか再度確認します。

git branch

(*が付いているブランチがご自身の作業ブランチになっていることを確認します)

8. 更新内容をmergeする。

更新元のブランチ(最新の状態にした maindevelop など)の変更を現在の作業ブランチに取り込みます。

git merge <更新元branch名>

例:main ブランチの変更を現在の作業ブランチにマージする場合

git merge main

例:develop ブランチの変更を現在の作業ブランチにマージする場合

git merge develop

これで、作業ブランチに最新の変更が反映されました。必要に応じてコンフリクトの解消などを行ってください。

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?