Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rename a git repository with submodules?

I have a git repository with submodules in the directory projects/myRepo and I want to rename the directory to projects/my-repo.

According to this question it can simply be done with mv. But in a repo with submodules git keeps telling me

fatal: Not a git repository: projects/myRepo/.git/path/to/submodule```

even for git status.

Submodule config:

[submodule "path/to/submodule"]  
   path = path/to/submodule  
   url = https://github.com/user/projectName.git  

Somehow the 'internal path' for the submodule does not get updated?! Is there a way to tell git to update these submodule paths?

like image 566
schmunk Avatar asked Mar 26 '12 19:03

schmunk


People also ask

Can you make changes to a git submodule?

Unfortunately, like removing submodules, Git does not make it clear how to update a submodule to a later commit. Fortunately though, it's not that tough. Initialize the repository's submodules by running git submodule init followed by git submodule update . Change into the submodule's directory.

What is submodules in github?

The subdirectory in a directory or Github repo inside another repository like using another project from within it is termed as a Submodule. Like when you are working in a repo and you want it to use at one of your parent repositories. You only add information about the submodule that is added to the main repository.

How do I add a submodule to a git repository?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.


3 Answers

Today I had the same problem to rename the submodule and finally I fixed it by using the following steps:

Assume the old module name is old/module and the new one is new/module/path

  1. at the root of the repo (repo_root), mv old/module new/module/path
  2. go to .git/modules
    1. mv old/module new/module/path (create the folder first if necessary)
    2. change new/module/name/config: update the worktree entry. It should be the relative path from this config file to repo_root/new/module/path
  3. go to repo_root and edit new/module/path/.git, change the gitdir to the relative path from this file to repo_root/.git/modules/new/module/path
  4. change .git/config of the master repo: find the line containing [submodule "old/module"] and update to [submodule "new/module/path"]
like image 97
doraemon Avatar answered Sep 21 '22 05:09

doraemon


I also had the same error after changing my project directory. I have an iOS 6 XCode 4 project but that shouldn't matter.

For each submodule, you need to change the absolute path that it thinks it's in. The path is set in the .git file for that submodule. .git in a submodule is a file as opposed to a directory in a standard git directory.

For each submodule, change the .gitdir line in the .git file. Here is an example from my project:

File: /path/to/project/submodules/RestKit/.git

Before gitdir: /path/to/project//.git/modules/submodules/RestKit

After gitdir: /path/to/project//.git/modules/submodules/RestKit

like image 27
Jon Deokule Avatar answered Sep 20 '22 05:09

Jon Deokule


I did experience exactly the same behavior. I managed to fix it by deleting directories with submodules, recreating them as empty directories with the right name and then running git submodule update --init to reinitialize them. All fixed now. Probably some permission problems (I retrieved those directories from backup earlier and permissions on them are sometimes strange).

like image 20
Honza Javorek Avatar answered Sep 17 '22 05:09

Honza Javorek