What's this?
「自分のアカウントにforkしてからプルリクエストしてね」って言われた時に実施するGitリモート設定のメモ。
前提
フォーク元にはmasterとdevelopブランチが存在し、developにプルリクエストする運用。
手順
- Githubでフォーク元リポジトリから自分のアカウントにforkする
- ローカル環境にforkしたリポジトリをcloneする
- gitリモート状態確認
% git remote -v
origin git@github.com:自分のアカウント名/リポジトリ名.git (fetch)
origin git@github.com:自分のアカウント名/リポジトリ名.git (push)
4.フォーク元リポジトリをupstreamとしてリモート追加
% git remote add upstream git@github.com:フォーク元アカウント名/リポジトリ名.git
5.gitリモート再確認
% git remote -v
origin git@github.com:自分のアカウント名/リポジトリ名.git (fetch)
origin git@github.com:自分のアカウント名/リポジトリ名.git (push)
upstream git@github.com:フォーク元アカウント名/リポジトリ名.git (fetch)
upstream git@github.com:フォーク元アカウント名/リポジトリ名.git (push)
6.フォーク元のdevelopブランチ(upstream)を追従させる
% git fetch upstream
* [new branch] develop -> upstream/develop
* [new branch] master -> upstream/master
% git branch -u upstream/develop develop
Branch 'develop' set up to track remote branch 'develop' from 'upstream'.
運用
% git branch
* develop
- 最新のdevelopブランチをフォーク元から取り込む
% git pull
- 取り込んだdevelopを元にブランチを作成し実装を開始
% git checkout -b example_feature
- (フォーク元に変更が有れば)随時取り込めば良い
% git checkout develop
% git pull
% git checkout example_feature
% git merge develop
- 実装が完了したらフォーク元のdevelopブランチに向けてプルリクエスト実施