I have a program divided into 3 packages. I have set up a local repo in one of the packages and set it up to push to a repo on gitHub. I have started work on the second package and I realized I haven't initialized it with git. I wanted to use the same gitHub repo to push the second package to but I'm not sure it will work since I have already set up my first package to push to it. I think I should have done git init on the parent folder of the three packages and then the folder/package structure would have shown up on my gitHub repo. Is there a simple way to fix this? Thanks!
-
This has a solution here: http://stackoverflow.com/questions/30629188/how-to-move-a-local-git-repository-to-the-root-folder-and-preserve-history/30629580#30629580 – Nick Volynkin Jun 09 '15 at 19:16
-
And here, somewhat less specific: http://stackoverflow.com/questions/19097259/how-to-move-a-git-repository-into-another-directory-and-make-that-directory-a-gi?lq=1 – Nick Volynkin Jun 09 '15 at 20:32
-
Thanks for the links! – ponder275 Jun 09 '15 at 23:08
2 Answers
Let's say your parent directory is named parent
, and your child directories are named package1
, package2
, and package3
. Let's also assume that package1
is the directory where you have your git repository. I would just make another package1
directory as a child of the original package1
directory, and move the contents of the original package1
directory into it. Then move package2
and package3
to be children of the original package1
. You can the rename the original package1
to parent. git add --all .
the whole thing, and you now have a repo with all three directories. The cool thing is that you will not lose the history of all the files you moved; git is smart enough to detect renames/moves.

- 17,443
- 4
- 47
- 54
Assume we have directory structure like this:
A
|
B
|
.git and other files
You should:
cd B
mkdir C
ls | grep -v '^C$' | xargs -L 1 -I '{}' git mv -r '{}' C/
ls ../ | grep -v '^B$' | xargs -L 1 -I '{}' mv ../'{}' .
git commit -am 'Change directory structure and include parent dir'

- 1,123
- 1
- 8
- 14
-
2Dumping complex shell commands into an answer without explanation isn't very helpful. Please add some context. – ChrisGPT was on strike Jun 09 '15 at 20:08