やりたいこと
Pull Requestをする時に、作業ごとにRequestを出したい。
例)
ログインページと新規登録ページを作り、別々にPull Requestを出したい。。
だけどRequestを二つ出してしまうと、なぜかRequestが一つのところにまとまってしまう。
原因
Branchを一つにしてしまっているから。
解決方法
Branchを作業毎に分ける。
やり方
①git branchで新たにbranchを作成する。
$ git branch login_button
②git checkout ブランチ名で作成したブランチに移動
$ git checkout login_button
※上記はgit checkout -b login_buttonとすることでブランチを作成しその後移動させることができる。
③git statusで変えたいファイルを確認する。
modified: app/views/sessions/new.html.erb
modified: app/views/users/new.html.erb
④git add ファイル名でstagingするファイルを指定
まずはログインページ(sessions/new)を指定する。
$ git add app/views/sessions/new.html.erb
git statusで現状を確認すると一つのファイルだけstagingされている
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: app/views/sessions/new.html.erb
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: app/views/users/new.html.erb
⑤コミット名を決めてgitにコミット
$ git commit -m 'modified login button'
⑥git push origin login_buttonとしてリモートリポジトリにpush
$ git push origin login_button
この時git push origin login_button:自分のつけたい名前とすることでリモートリポジトリにpushすると、リモートリポジトリには自分のつけたい名前が反映される。
この後GitHub上でPull Requestをすると下のようになる。
⑦branchの名前をsignin_buttonとして①~⑥を繰り返す。
⑧Pull Requestが作業毎に出来る
結論
Pull Requestを出すときはBranchを分けることによって、作業毎にRequestを出すことができる。