Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).
<The correct solution is:
mv oldpath ~/another-location
git rm oldpath
git submodule add submodule-repository-URL newpath
Source: Rename git submodule
I found following workflow working:
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and .gitmodules properly in 2018 versions of GIT.
Note: You may be able to now just do git mv oldpath newpath
now, as pointed out in VonC's answer. (Ensure you are using the latest version of git)
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a git submodule sync
afterwards, but I'm not in a position to check right now.
MacOs: When I wanna use VonC solution to change submodule folder Common
to lowercase:
git mv Common common
I get
fatal: renaming 'Common' failed: Invalid argument
Solution - use some temporary folder name and move twice:
git mv Common commontemp
git mv commontemp common
That's all :)
It's not possible to rename it, so you've to remove it first (deinit
) and add it again.
So after removing it:
git submodule deinit <path>
git rm --cached <path>
you may also double check and remove the references to it in:
.gitmodules
.git/config
.git/modules/<name>
(best to make a backup), as each folder has config
file where it keeps the reference to its worktree
then stage your changes by committing any changes to your repo by:
git commit -am 'Removing submodule.'
and double check if you don't have any outstanding issues by:
git submodule update
git submodule sync
git submodule status
so now you can add the git submodule again:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
I just tried a few of the suggested above. I'm running:
$ git --version
git version 1.8.4
I found it was best to de-init the submodule, remove the directory and create a new submodule.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
At least that is what worked for me best. YMMV!