LoginSignup
51
51

More than 5 years have passed since last update.

gitでリモートリポジトリを同期する

Posted at

リモートリポジトリの設定を勝手にいじれないけど、同期しないといけないときの方法。

ポイントはgit clone --mirror
git clone --initだとgit fetch --allでローカルのHEADは更新されない(→pushできない)が、git clone --mirrorだとtracking属性が付与されるのでローカルのHEADも更新され、二回目以降が楽。

  • 初回
    git clone --mirror /homge/GIT/sample-repo1.git
    cd mirror-repo1
    git remote add origin2 /home/GIT/sample-repo2.git
    git push origin2 --mirror
  • 2回目以降
    git fetch --all
    git push origin2 --mirror

上記の問題は片方向の同期しかできていないこと。
逆方向の同期も合わせて行う方法もあるけど、余計なトラブルを避けるなら運用でカバー(sample-repo1にしかコミットしない)かな。

ちなみに、git push origin2 --mirrorでタグもブランチも同期。git push origin2 --allでブランチだけ同期。ちょっと直感に反するので注意。

51
51
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
51
51