※当サイトの記事には、広告・プロモーションが含まれます。

Gitのリポジトリ構成、Monolith、Multi-repo、Monorepo、Polyrepo、どれが実現できるの?

nazology.net

アメリカ・ペンシルバニア大学(UPenn)電気システム工学科に所属するファシッド・アシティアニ氏ら研究チームが、1秒間に20億枚の画像処理が可能なニューラルネットワークを開発したのです。

電気信号に変換せず光のまま考える!? 1秒間に20億枚の画像処理をするチップを開発! - ナゾロジー

従来は光を電気に変換してから処理していましたが、光のまま処理できるシステムを作ることで、処理速度を大きく向上させています。

電気信号に変換せず光のまま考える!? 1秒間に20億枚の画像処理をするチップを開発! - ナゾロジー

⇧ amaizing...

Gitのリポジトリ構成、Monolith、Multi-repo、Monorepo、Polyrepo、どれが実現できるの?

ググってはみたものの、そもそもとして、リポジトリ構成について

  • Monolith
  • Multi-repo
  • Monorepo
  • Polyrepo

の出処が謎なんですよね...

uploadcare.com

Monorepositories and polyrepositories are relatively new discussion topics. The first mention of monorepo on Twitter is from 2011 (or from 2010, if we count the phrase “mono repo”). The first tweet containing the word “polyrepo” is from 2013. These are two approaches to organizing your source code in either one repository or multiple repositories.

https://uploadcare.com/blog/monorepository-and-polyrepository-two-poor-solutions-part/

It’s worth noting that there is no agreement on the name of polyrepo. The word “multirepo” is also in use, and it appeared even earlier than the other two.

https://uploadcare.com/blog/monorepository-and-polyrepository-two-poor-solutions-part/

⇧ 2010年代に出てきた言葉ではあるらしい。

調べた限りでは、

monorepo.tools

⇧ 4種類に分類できるってことみたい。

ネットの情報によると、

engineering.mercari.com

circleci.com

⇧「Monorepo」か「Polyrepo」が良いとのことなんだけど、それぞれの定義とかも曖昧な感じなので、違いがよく分からんのよね...

Monorepoを試してみる

で、「Monorepo」が良いよ、とおススメしてる割には、「Monorepo」の始め方については、良さ気な情報が見当たらない...

何なんだろうね...

www.shopsys.com

This is the most frequent question when it comes to monorepo adoption in companies. And usually the last one because it’s rejected out of hand as requiring too much effort and resources.

https://www.shopsys.com/how-to-merge-15-repositories-to-1-monorepo-keep-their-git-history-and-add-project-base-as-well-6e124f3a0ab3/

Since we already had 15 repositories and a project-base with over 8000 commits in total, the option of dropping git history for all of them was off the table as well.

https://www.shopsys.com/how-to-merge-15-repositories-to-1-monorepo-keep-their-git-history-and-add-project-base-as-well-6e124f3a0ab3/

After struggling to find ways to resolve this problem, one of our programmers Petr Heinz devoted a considerable number of work-hours to coming up with a package: monorepo-tools.

https://www.shopsys.com/how-to-merge-15-repositories-to-1-monorepo-keep-their-git-history-and-add-project-base-as-well-6e124f3a0ab3/

⇧ 上記サイト様によりますと、ツール使わないと大変ってことらしいのですが、そもそも大変も何も、その「Monorepo」の始め方が分からないんだって話なんだけどね...

で、そもそも、普通にGitHubGUIだと、Repositoryを「Monorepo」で作るってのは無理っぽい。

じゃあ、どうするのか?

mattmazzola.medium.com

⇧ 上記サイト様によりますと、GitHub上で作ったRepositoryに対してgitコマンドで「Monorepo」にするしかないっぽい、つまりCUIで頑張るしかない模様。

というわけで、上記サイト様を参考に試してみる。

まずは、GitHubにログインして、「Monorepo」用のRepositoryを作成。

今回は、既に、GitHubに作成してる以下の2つのRepositoryで「Monorepo」を構成することにします。

「Monorepo」用のRepositoryをローカル環境にcloneで、怒られる。

koko206.hatenablog.com

⇧ 上記サイト様を参考に、GitHubのRepositoryの一覧を確認したところ、Repository自体は作成されている。

どうやら、initialなんてブランチが存在しないと言うことらしい、GitHubでRepositoryを作成した直後に、initialなんていうブランチは作成されていないってことですかね。

ブランチ指定せず、cloneで。

「Monorepo」用のRepositoryに、別のRepositoryを追加。

で、一旦、リモートリポジトリ(GitHubのRepository)に反映しようとしたら、

そもそも、commitできない...

stackoverflow.com

torek's answer is probably perfect, but I just wanted for the record to mention another case which is different than the one described in the original question but the same error may appear (as it may help others with similar problem):

I have created an empty (new) repo using git init --bare on one of my servers. Then I have git cloned it to a local workspace on my PC.

After committing a single version on the local repo I got that error after calling git status.

Following torek's answer, I understand that what happened is that the first commit on local working directory repo created "master" branch. But on the remote repo (on the server) there was never anything, so there was not even a "master" (remotes/origin/master) branch.

After running git push origin master from local repo the remote repo finally had a master branch. This stopped the error from appearing.

So to conclude - one may get such an error for a fresh new remote repo with zero commits since it has no branch, including "master".

https://stackoverflow.com/questions/21609781/why-call-git-branch-unset-upstream-to-fixup

⇧ なんか、リモートリポジトリ(GitHubのRepository)が空の時にも起きる問題らしい。

git commitやgit addをせずにgit pushしてしまえば良いらしい。

「Monorepo」用のRepositoryに、Repositoryが追加されました。

続いて、もう一つのRepositoryを追加しようとして、エラー。

存在しないと怒られる。

ja.stackoverflow.com

⇧ 上記サイト様を参考に確認。

分からんけど、リモートリポジトリ(GitHubのRepository)が空じゃなくなると、相対パスが効かなくなるんかな、

qiita.com

⇧ 上記サイト様を参考に、一旦、既存のものを削除してから改めて絶対パスにして追加し直したところ、

いけました。

「Monorepo」用のRepositoryに、マージ。

で、git pushしたところ、

反映されました。

何て言うか、フロントエンドのプロジェクトである「my-project-vue」のフォルダ構成が散らかってたせいで、カオスな感じになってしまったけども、「Monorepo」が実現できたってことで良いんかな?

毎回モヤモヤ感が半端ない...

今回はこのへんで。