<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Development on oinume journal</title>
    <link>https://blog-lampetty-net.web.app/tags/development/</link>
    <description>Recent content in Development on oinume journal</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>ja</language>
    <lastBuildDate>Tue, 22 Jul 2025 08:00:00 +0900</lastBuildDate><atom:link href="https://blog-lampetty-net.web.app/tags/development/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>複数のプロダクトのリポジトリをMonorepoに移行する</title>
      <link>https://blog-lampetty-net.web.app/posts/migrate-polyrepo-to-monorepo/</link>
      <pubDate>Tue, 22 Jul 2025 08:00:00 +0900</pubDate>
      
      <guid>https://blog-lampetty-net.web.app/posts/migrate-polyrepo-to-monorepo/</guid>
      <description>
        
          
            &lt;p&gt;表題の通り、技術スタックがほぼ同じプロダクト群のリポジトリを1つのMonorepoにまとめてみたという雑な記録。&lt;/p&gt;
&lt;p&gt;元々は以下のようなPolyrepo構造になっていた。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;product-a (repository)
&lt;ul&gt;
&lt;li&gt;backend&lt;/li&gt;
&lt;li&gt;web&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;product-b (repository)
&lt;ul&gt;
&lt;li&gt;backend&lt;/li&gt;
&lt;li&gt;native&lt;/li&gt;
&lt;li&gt;web&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;これを以下のような構成に移行した。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;products (repository)
&lt;ul&gt;
&lt;li&gt;apps
&lt;ul&gt;
&lt;li&gt;product-a
&lt;ul&gt;
&lt;li&gt;backend&lt;/li&gt;
&lt;li&gt;web&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;product-b
&lt;ul&gt;
&lt;li&gt;backend&lt;/li&gt;
&lt;li&gt;native&lt;/li&gt;
&lt;li&gt;web&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;大まかには以下のような流れで移行する。&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;移行元のリポジトリで移行用ブランチを作成する&lt;/li&gt;
&lt;li&gt;移行先のリポジトリで移行用ブランチを作成し、1.の移行用ブランチをmergeする&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;では実際に移行してみよう。&lt;code&gt;product-a&lt;/code&gt;のリポジトリで以下のコマンドを実行する。&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;mkdir -p apps/product-a
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git checkout -b monorepo
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git mv -k * apps/product-a/  # -k is used to ignore the error that it can&amp;#39;t move the projects directory
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git mv -k .* apps/product-a/  # .* to move .gitignore and other dot files
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;次に移行先の&lt;code&gt;products&lt;/code&gt;リポジトリで以下のコマンドを実行する。&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git remote add -f product-a https://github.com/&amp;lt;owner&amp;gt;/product-a.git
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git checkout -b import-product-a
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git merge product-a/monorepo --allow-unrelated-histories
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;これで products リポジトリの &lt;code&gt;import-product-a&lt;/code&gt;というブランチにproduct-aリポジトリのファイルが追加されているので、pull-requestを作るなどしてこのブランチをmainブランチにマージすればOK&lt;/p&gt;
          
          
        
      </description>
    </item>
    
  </channel>
</rss>