16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitリポジトリ内に完全に別のgitリポジトリを作りたい

Posted at

すんごい小ネタ。

サブモジュールとか--subdirectory-filterとかは出てくるんだけど、ちゃうねん、単に完全に一切全く無関係の別のリポジトリが作りたいだけなんだよ。

という問題に何故か直球の答えが見つからなかったのでここに書いておく。
簡単すぎて常識だから逆に誰も書いてないのかもしれない。

手順

元々外側のリポジトリがあって、そこに別のリポジトリpath/to/otherproject/を作りたいとする。

外側のリポジトリ

まず外側のリポジトリから見えなくするために.gitignoreを書く。

/path/to/otherproject/

もし既に外側のリポジトリに入ってしまっているようなら、リポジトリから削除する。

git rm -r --cached path/to/otherproject

--cachedを入れるとリポジトリから消すだけでファイルは残る。入れなければファイルごと削除。

内側のリポジトリ

単にgit initするだけ。

cd path/to/otherproject
git init

その後はotherprojectディレクトリ内であればotherprojectのgitを見るし、ディレクトリ外では外側のリポジトリを使えるようになる。
めでたしめでたし。

その他

.gitignoreを書かなければ、外側のリポジトリが内側のリポジトリを自動的にサブモジュールとして扱ってくれるみたい。

感想

そもそもgitリポジトリ内に全く別のリポジトリを作るという運用を見直したほうがいいという意見には賛成。

16
14
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
16
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?