Zvika
Zvika

Reputation: 1702

GIT - how to properly 'git init' a git repository's 'upper' directory

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?

Upvotes: 1

Views: 355

Answers (2)

JDurstberger
JDurstberger

Reputation: 4255

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

Upvotes: 1

Nils_M
Nils_M

Reputation: 1090

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.

Upvotes: 0

Related Questions