LoginSignup
3
3

More than 5 years have passed since last update.

別 remote の commit を pull(merge) する

Last updated at Posted at 2014-09-25

諸事情でソースコード管理が分化しちゃってる場合とか。
あんま無いだろうけど、別々の Github Enterprise インスタンス、とかね。

git@xxx:sample.git に、git@yyy:sample.git の修正を引っ張ってくる。

適当な名前で remote 登録。今回は upstream で。

$ git remote add upstream git@yyy:sample.git

remote が追加されたこと確認して

$ git remote -v
origin  git@xxx:sample.git (fetch)
origin  git@xxx:sample.git (push)
upstream    git@yyy:sample.git (fetch)
upstream    git@yyy:sample.git (push)

fetch しーの

$ git fetch --all
Fetching origin
Fetching upstream
...

upstream から、欲しい branch を pull する。今回は master。
origin 側に独自に修正入れて無ければ、Fast-forward になりそう。

$ git pull upstream master
From yyy:sample
 * branch            master     -> FETCH_HEAD
Updating d2aed11..c812006
Fast-forward
...

終わったら origin に push しておく。

$ git push origin master

(追記)
ngyuki さんから下記指摘いただきました。

pull って fetch + merge なのでその手順でやるなら fetch → merge の方が良いかなと思います。

知らなかった…ってことで、man git-pull 確認。まんま書いてありましたね…。
ご指摘の通り、敢えて fetch 別に叩いてるなら、merge のほうが自然ですね。

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.
3
3
3

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
3