Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand git repo

Tags:

git

I've got some code that looks like this on the file system:

1.java
A/a.java

The code in A is contained in a git repo.

However, I now want to expand the repo to cover the entire code base (i.e. including 1.java which is 1 directory up).

I've got a feeling (having played around with submodules) that it's not as easy as just init'ing a git repo in the parent directory. Am I right? If so, how should I tackle this?

like image 954
Snowcrash Avatar asked Feb 22 '26 16:02

Snowcrash


1 Answers

cd A
mkdir A
git mv -k * A/
git commit -m "Expand git repo"
cd ..
mv A tmpA
mv tmpA/{.git,A} ./
rmdir tmpA

In other words, do the reorg inside the repo, then just move everything up a directory. Git won't know the difference because all of the filenames will match.

The mv -k stops git from trying to move A/ into itself, which would be an error.

like image 82
Max Avatar answered Feb 25 '26 14:02

Max



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!