LoginSignup
2
1

More than 3 years have passed since last update.

Githubでforkした時のGitリモート設定例

Last updated at Posted at 2020-03-12

What's this?

「自分のアカウントにforkしてからプルリクエストしてね」って言われた時に実施するGitリモート設定のメモ。

前提

フォーク元にはmasterとdevelopブランチが存在し、developにプルリクエストする運用。

手順

  1. Githubでフォーク元リポジトリから自分のアカウントにforkする
  2. ローカル環境にforkしたリポジトリをcloneする
  3. 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ブランチに向けてプルリクエスト実施
2
1
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
2
1