LoginSignup
3
0

More than 1 year has passed since last update.

forkしたレポジトリの更新とupstreamについて

Last updated at Posted at 2020-03-19

Gitでforkしたブランチを最新の状態に更新する方法と、それを調べたとき出てきたupstreamという概念についてのメモ。

1. forkしたレポジトリを最新の状態に更新する

Github上でレポジトリをforkしたあとの話。

$ git clone git@github.com:アカウント名/forkしたレポジトリ.git    #とりあえずforkしたレポジトリをclone
$ cd forkしたレポジトリ
$ git branch    #ブランチを確認
  * master
$ git remote -v    #リモートの状態を確認
  origin https://github.com/アカウント名/forkしたレポジトリ.git (fetch)    #自分のアカウントにあるレポジトリが指定されている
  origin https://github.com/アカウント名/forkしたレポジトリ.git (push)
$ git remote add upstream git://github.com/fork元のレポジトリ.git    #本家をupstreamとして追加
$ git remote -v    #リモートの状態を確認
  origin https://github.com/アカウント名/forkしたレポジトリ.git (fetch)    #自分のアカウントにあるレポジトリが指定されている
  origin https://github.com/アカウント名/forkしたレポジトリ.git (push)
  upstream https://github.com/fork元のレポジトリ.git (fetch)    #本家のレポジトリが指定されている
  upstream https://github.com/fork元のレポジトリ.git (push)
$ git checkout master
$ git fetch upstream    #upstreamに対してfetch
$ git git merge upstream/master    #upstreamのmasterからマージ

2. upstreamって何よ?

  • Gitでの慣例として、自分のリポジトリは「origin」、フォーク元は「upstream」とする。
  • origin に対しては read / write ができるが、upstream に対しては read だけができる。

参考:Flight rules for Git

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