1

I have a directory ./a/b/. Only b is a git repo. Now I've decided that the git repo tree should start from a, and include (if possible) all information about b repo.

I've tried to just git init from a, and commit. But when a is cloned, it has an empty b. (which is interesting, because as far as I know git usually ignores empty directories)

It it possible to do this somehow?

Zvika
  • 1,542
  • 2
  • 17
  • 21

2 Answers2

1

Just cut and paste your .git folder to a and add everything.

mv .git ../.git  #move the repo  
cd .. #go to the parent dir
git add --all  #add everything
git commit -m 'moves everything into a subfolder'  #commit everything

git will recognise everything as "renamed": (example with one file)

git status
On branch master
Changes to be comitted:
(use "git reset HEAD ..." to unstage)

renamed: test -> b/test

JDurstberger
  • 4,127
  • 8
  • 31
  • 68
0

I propose to stay in your repo in ./a/b and move all tracked files to a subdirectory ./a/b/a/b via git mv filename. After this your repo has the correct structure which is everything which really counts. You can then move the whole repo to . to get exactly what you want. git mv supports the usage of wildcards to make this easier.

Related question. You can get a bit more automation via this answer.

Community
  • 1
  • 1
Nils_M
  • 1,062
  • 10
  • 24