Githubで活発に開発されているプロダクトの最新ブランチに追従しながら開発を進めていくための方法をEC-CUBE4を例に紹介します。
とりあえずFork
とりあえず本家のレポジトリをフォークする
EC-CUBEのリポジトリで、右上のForkボタン押す。
次にclone
自分のレポジトリからcloneする
$ git clone https://github.com/ユーザ名/ec-cube.git
ブランチの状態を確認してみる
$ git branch -a
* master
remotes/origin/4.0
remotes/origin/HEAD -> origin/master
これでまずはソースコードをローカルに持ってきました
本家レポジトリの追従
本家が更新されても追従できるように、本家レポジトリをupstreamとして登録
$ git remote add upstream https://github.com/EC-CUBE/ec-cube.git
$ git remote -v
origin https://github.com/ユーザ名/ec-cube.git (fetch)
origin https://github.com/ユーザ名/ec-cube.git (push)
upstream https://github.com/EC-CUBE/ec-cube.git (fetch)
upstream https://github.com/EC-CUBE/ec-cube.git (push)
originには自分のが、upstreamには本家が登録されてるのがわかります。
この状態ではまだupstreamの情報を取得していないので一度fetchしておきます。
$ git fetch upstream
開発する時の流れ
ローカルに開発用ブランチを作成
$ git checkout -b ブランチ名 upstream/4.0
GitHubの自分のレポジトリに反映
$ git push origin ブランチ名
開発する
.
.
.
完了したらコミット
$ git add /path/to/file
$ git add /path/to/file
$ git commit -m "コメント"
本家の変更を確認
$ git fetch upstream
何か変更があればとってくる
本家の変更をマージ
$ git merge upstream/4.0
何か変更があれば、マージする
自分のレポジトリにpush
$ git push origin ブランチ名 -f
プルリクを送る
GitHubの自分のレポジトリから、PullRequestする