Expand git repo

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.

  • Merge/rebase a 'disconnected' branch in Git
  • Git Submodules. Pulling into a new clone of the super-project
  • How to modify a pull request on GitHub to change target branch to merge into?
  • Is there an easy way to manage multiple versions of git?
  • How to merge in JGit?
  • git maintaining 2 versions of the same project, with different users on each
  • 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?

  • Git Revert “revert is not possible because you have unmerged files”
  • How can I install from a git subdirectory with pip?
  • Where's the 3-way Git merge driver for .PO (gettext) files?
  • Accept all merge conflicts in git
  • Setting up Notepad++ Compare as the diff tool in git?
  • Cloned Gist but want to rename folder
  • One Solution collect form web for “Expand git repo”

    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.

    Git Baby is a git and github fan, let's start git clone.