Sub Documents
Gitでリモートブランチを複数登録する
通常何もしなければリモートリポジトリは1つだけ登録されていると思います。
$ git remote -v
origin git@github.org:something/repos1.git (fetch)
origin git@github.org:something/repos1.git (push)
こういう状態に対して、複数のリモートリポジトリを登録することができます。
- remote repos1 (repos1) → origin
- remote repos2 (repos2) → foo
- remote repos3 (repos3) → bar
originからpullしてfooにpushするみたいなことができます。主に大規模開発で使われる手法かと思います。
$ git remote add foo git@bitbucket.org:something/repos2.git
$ git remote add bar git@bitbucket.org:something/repos3.git
こんな感じで、foo
bar
の部分に任意の文字列で指定します。
$ git remote -v
bar git@bitbucket.org:something/repos3.git (fetch)
bar git@bitbucket.org:something/repos3.git (push)
foo git@bitbucket.org:something/repos2.git (fetch)
foo git@bitbucket.org:something/repos2.git (push)
origin git@github.org:something/repos1.git (fetch)
origin git@github.org:something/repos1.git (push)
こういうかたちになります。
実際にpushやpullをするときは、
$ git pull origin main
$ git push foo main
$ git push bar main
のような使い方をします。fetchやmergeも同樣のやり方になります。