LoginSignup
1
0

More than 3 years have passed since last update.

本家リポジトリにローカルリポジトリを追従させたい

Posted at

前提

  1. 本家リポジトリはorigin/master
  2. 本家リポジトリをforkし、リモートリポジトリorigin/masterができた
  3. リモートリポジトリをcloneし、ローカルリポジトリorigin/masterができた
  4. commitが先に進んだ本家リポジトリorigin/masterの変更を、ローカルリポジトリorigin/masterに反映させたい

1

まず、作業ディレクトリに移動する。

本家リポジトリをupstreamという名でローカルに登録する。upstreamの箇所は、新しいものであれば、何でもよい。

git remote add upstream <本家リポジトリのURL>

この作業は、初回のみでよい。

2

ローカルでupstreamと名付けた本家リポジトリを、ローカルリポジトリにpullする。

git pull upstream <pull元のbranch>:<pull先のbranch> --allow-unrelated-histories

今回の条件設定では、本家upstream/masterから、ローカルのorigin/masterにpullをするので、git pull upstream master:master --allow-unrelated-historiesとなった。

また、ローカルリポジトリにないファイルを本家リポジトリにからpullするのに、オプション--allow-unrelated-historiesを用いる。Gitが追跡していないファイルをpullする際に必要だ。

参考

1
0
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
1
0