LoginSignup
21
16

More than 5 years have passed since last update.

githubで他人の作成中のブランチをローカルに持ってくる方法

Posted at

チーム開発でgithubを使っているとき、互いにコードレビューを行ってコードの質を上げるということをやっているチームは世の中に多くあると思います。

そういったことをする過程で、サーバー側のコードならgithub上でソースコードを読めばたいがいわかりますが、フロント側のコードは読むだけでは不十分な場合が多くあります。実際の動きを自分のローカルで再現してレビューをする必要が出てきたりします。

そんなとき、どうやって他人の開発中のブランチを手元に持ってきて再現するか、ということです。

やりかた

まず、

git checkout origin/[ブランチ名]

というコマンドを打ちます。そうすると、おそらくリモートリポジトリのブランチにcheckoutしている状態になります。

そして、このコマンドを打つと親切にも以下のような文章が出てきます。

Note: checking out 'origin/[ブランチ名]'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

まぁ、要するに自分のローカルのブランチにしたいなら、今いるブランチ(リモートの他人が開発途中のブランチ)をもとにローカルに新しいブランチ切ってね、ということ。

そこで、

git checkout -b wip_branch

とすれば、自分のローカルに他人が開発途中のブランチをwip_branchとして取ってこれるわけです。

21
16
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
21
16