I never expect renaming a git repo, which, more specifically, is the top-level folder holds the project, would be so hard. Yes, the project containing some submodules, but it is
You also need to check each sub-module's gitdir
.
It should be in sub-module's folder .git
file.
When moving a project that has git submodules from one folder to another, on the same machine, there are some hardcoded links that have to be updated.
First, all submodules have a .git file where they store the absolute path to their git configuration folder ( these are inside the main's project .git folder, grouped into the modules folder). To fix all of these, run the following command from the root of the main project:
find . -name .git -print0 -type f | xargs -0 sed -i 's|<OLD PATH>|<NEW PATH>|g'
Second, the configuration files for the git submodules have a line where the working directory is saved, also absolute. To update all of the references at once, run the following command from the root of the main project:
find . -name config -print0 -type f | xargs -0 sed -i 's|<OLD PATH>|<NEW PATH>|g'
The assumptions made are that your OS is some form of *nix, and that you have the package sed installed.
You need to actually modify two files
.git/modules/<path-to-submodule>/config
<path-to-submodule>/.git
You have a couple of options, they end up being the same thing:
clone again
Instead of renaming the folder - just clone again
$ cd /project/original
$ cd ..
$ mkdir moved
$ git init
$ git pull ../original master
$ git submodule init
$ git submodule update
Compare original/.git/config
to moved/.git/config
and address any significant differences (missing branches need creating - missing remotes just need adding to the config file).
fix paths
You can rename your project folder, it just needs a little tweaking.
I.e. these files:
$ cd /project/moved
$ find -name .git -type f
All you need to do is edit them to point at the right directory
I.e. these files:
$ cd /project/moved
$ find .git/modules/ -name config
Here, update the worktree
setting:
[core]
...
worktree = /original/path/submodule
To
[core]
...
worktree = /moved/path/submodule
And that's it.
A note about versions
1.7.8 introduced the use of a .git file for submodules and used absolute paths, this was fixed in 1.7.10 - therefore the problem only applies to git repos created with git version 1.7.8, and 1.7.9.