0
2

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でよくある操作「pull後のブランチ切り替え」を整理してみた

Posted at

はじめに

Gitで作業を進めていると、pullした内容を確認したり、別のブランチに移動して作業を続けたくなることがあります。

個人の備忘録程度の走り書きとなっておりますが、温かい目で見守っていただければ幸いです。

この記事では、pull後にブランチを切り替える基本的な手順についてまとめます。

書こうと思ったきっかけ

実際のチーム開発でGitを使っている際に、pull後に他のブランチへ移動したくなった時、正しい方法をすぐに思い出せなかった経験がありました。その備忘録として、よく使う切り替えコマンドを整理しました。

Gitでpullした後にブランチを切り替える方法

すでにローカルに存在するブランチに切り替える場合

git checkout ブランチ名

例:

git checkout feature/login-page

ローカルに存在しない(リモートにだけ存在する)ブランチに切り替える場合

git checkout -b ブランチ名 origin/ブランチ名

例:

git checkout -b feature/login-page origin/feature/login-page

ブランチの確認方法

  • ローカルブランチ一覧の確認:
git branch
  • リモートブランチ一覧の確認:
git branch -r

補足:git switch コマンドについて

Gitのバージョンが2.23以降であれば、git checkoutの代わりに git switch を使うこともできます。

git switch ブランチ名

もしくは、新しいブランチを作って切り替える場合:

git switch -c 新しいブランチ名

参考文献

まとめ

pull後にブランチを切り替えるには、git checkout あるいは git switch を使い分けることでスムーズに作業を進めることができます。ブランチの状態や存在場所(ローカル or リモート)によって、適切なコマンドを選びましょう!

0
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?