はじめてのpull request - リモートブランチのmaster じゃないブランチにpull request

githubではじめてpull request をしたのですが、その時躓いたところとか書いていこうかと思います。
masterブランチへのpull requestはGitHubへpull requestする際のベストプラクティス - hnwの日記によくまとまっているので、参考になりました。

pull request するときは必ずforkした自分のレポジトリに対して操作をしましょう!

forkした自分のリポジトリをcloneする

$ git clone https://github.com/kmn/tonicdnscli.git

fork元リポジトリ(https://github.com/mkouhei/tonicdnscli.git) *1をupstreamという名で登録する。

$ git remote add upstream https://github.com/mkouhei/tonicdnscli.git

リモートレポジトリを確認します。

$ git remote -v
origin     git@github.com:kmn/tonicdnscli.git (fetch)
origin     git@github.com:kmn/tonicdnscli.git (push)
upstream     https://github.com/mkouhei/tonicdnscli.git (fetch)
upstream     https://github.com/mkouhei/tonicdnscli.git (push)

git clone したものは "origin"として登録されます。
upstreamという名前が登録されていることが確認できます。

ブランチを確認します。

% git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/devel
  remotes/origin/master
  remotes/origin/refactoring
  remotes/origin/unittest
  remotes/upstream/devel
  remotes/upstream/master
  remotes/upstream/unittest

git branch -l だとローカルリポジトリだけ見ることができます。

リモートレポジトリ(upstream)のdevelブランチをコピーしてローカルブランチ local_develを作成し,local_develにうつる。

$ git checkout -b local_devel upstream/devel   

説明が長いですね。でも、でも、そういうことなんです。

ローカルブランチ(local_devel) をリモートリポジトリ(origin)のdevel ブランチにpush する。

$ git push origin local_devel:devel

プッシュしたコミットをgithub上からpull request します。


参考
EZ-NET 特集: リモートブランチを操作する - Git による版管理環境を構築する
Git Workflow · NancyFx/Nancy Wiki · GitHub
GitHubへpull requestする際のベストプラクティス - hnwの日記

*1:今回pull request したプロジェクトです。ブランチが複数ある例として使わせていただきました。