1

I created a submodule to display the code i did for my class (lesson class not code class) in my github website.

The first class I did was learn to program HTML, so i made a repository for it. Then I created a submodule to link the code with the site. This worked well. Then I started the next class, CSS.

Then I thought instead of several repositories (and submodules) that I would group all my classes under one repository. The problem is that when I created the submodule it took a name from somewhere, I never explicitly specified one. It took the name "ltp-html5-authoring" and appends it before everything. It doesnt look too bad for the link to the first class, ltp-html5-authoring/ltp-html5-authoring/ltp-html5-authoring.html but is downright wrong with the second one. ltp-html5-authoring/ltp-css3-specialist/ltp-css3-specialist.html And will continue to be wrong as I add folders.

Is there any way to rename the submodule or do I have to remove it and re-add it?

git mv

Does not work because the name of the submodule does not exist as part of any folder. The name is prefixed to the url of the submodule so it becomes

I issued:

C:\Code\site>git submodule foreach -q git config remote.origin.url
https://github.com/Marvelous-Software/ltp-html5-authoring.git

I tried:

C:\Code\site>git submodule set-url ltp-html5-authoring https://github.com/Marvelous-Software/Frameworktv.git

and

C:\Code\site>git submodule set-url https://github.com/Marvelous-Software/ltp-html5-authoring https://github.com/Marvelous-Software/Frameworktv

Although I didn't expect that to work since the parameter set-url is not what I want to do and it did not work anyway.

Where the path is https://github.com/Marvelous-Software/Frameworktv.git And the path to a landing page is https://marvelous-software.github.io/school/ltp-html5-authoring/ltp-html5-authoring/ltp-html5-authoring.html whish is

user14202986
  • 153
  • 1
  • 1
  • 9

2 Answers2

4

Unfortunately I have been unable to determine if a submodule can be renamed. While testing I tried to create a new submodule explicitly setting the name using this command:

git submodule add https://github.com/Marvelous-Software/FrameworkTelevision.git --name Frameworktv

I used the --name parameter based on this:

C:\Code\site>git submodule -?
usage: git submodule [--quiet] [--cached]
   or: **git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>]** [--reference <repository>] [--] <repository> [<path>]
   or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
   or: git submodule [--quiet] init [--] [<path>...]
   or: git submodule [--quiet] deinit [-f|--force] (--all| [--] <path>...)
   or: git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
   or: git submodule [--quiet] set-branch (--default|--branch <branch>) [--] <path>
   or: git submodule [--quiet] set-url [--] <path> <newurl>
   or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
   or: git submodule [--quiet] foreach [--recursive] <command>
   or: git submodule [--quiet] sync [--recursive] [--] [<path>...]
   or: git submodule [--quiet] absorbgitdirs [--] [<path>...]

And this created a submodule called --name!

Well now I had a mess to clean up and git commands would not work using --name as the name because it was interpreted as a parameter. So I removed the linked folder in the parent. I deleted the submodule folder in .git/modules. Then I removed the entry in the .git/config, i found the name --name in there. Maybe I could've changed the name there in the first place, I didn't check the config file before deleting the original submodule.

But after I cleaned everything back up I created a new submodule named Frameworktv with this command:

git submodule add https://github.com/Marvelous-Software/FrameworkTelevision.git Frameworktv

And it works perfect!

https://marvelous-software.github.io/Frameworktv/ltp-html5-authoring/ltp-html5-authoring.html

Code from config:

[submodule "Frameworktv"]
    url = https://github.com/Marvelous-Software/FrameworkTelevision.git
    active = true
user14202986
  • 153
  • 1
  • 1
  • 9
  • The submodule was registered as "--name" because you passed it as positional ` []` argument, not as option. To be recognized as option it needs to be placed before the repository URL. – Tom Jan 25 '23 at 15:24
-1

Check first your main repository .gitmodules content: the ltp-html5-authoring should be part of the path associated with each of your submodules.

If the path is wrong, you can (preferably with Git 2.18 or more) use git mv to move the submodule.

git mv  ltp-html5-authoring/ltp-css3-specialist anotherPrefix/ltp-css3-specialist 
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Well I do not wish to move anything, its all where it should be. The name is wrong. I need to fix the name. I would like to rename the submodule instead of deleting it then re-adding it. – user14202986 Sep 15 '20 at 19:56
  • @user14202986 You can fix the name by using `git mv`. That will rename it. – VonC Sep 15 '20 at 20:02
  • And how would I do this? Do you have an example? I see no options for name. And the source and destination are the same so I don't see how that could work. Keep in mind that this is a submodule that I am speaking of. – user14202986 Sep 15 '20 at 21:20
  • @user14202986 OK, I through you were referring to the path. The name itself should be editable in the `.gitmodules` file. – VonC Sep 15 '20 at 21:32
  • So do I edit my local copy and do a push? Will this update it on the server? – user14202986 Sep 16 '20 at 10:16
  • Yes, it will update the name, not the path. Again, by editing the .git modules file. – VonC Sep 16 '20 at 10:18
  • That doesn\t work. I renamed the file and now receive an error: "fatal: not a git repository: school/ltp-html5-authoring/../../.git/modules/school/ltp-html5-authoring – user14202986 Sep 17 '20 at 00:41
  • I think you are confusing a name with a path. I see the path under .gitmodules but not the name. Perhaps if you told me where this name was I may be able to find it. – user14202986 Sep 17 '20 at 00:47
  • @user14202986 you said path was OK, since `git mv` was not needed. Are you actuellay referring to the associated submodule URL? That one can be changed (since Git 2.25) with `git submodule set-url`: see https://stackoverflow.com/a/914135/6309. – VonC Sep 17 '20 at 07:16
  • thanks for your reply. I do not need to change the path. I do not need to change the url. All locations are as they should be. I need to change the NAME. Only the NAME, not any path, url or link. All paths, urls and links (except the one with the embedded name) are fine and changing them will produce inconsistency that I wish to avoid. Yes I am referring to the submodule url which include the path (or url) prefixed by the NAME. The name does not exist anywhere in any path or url, hence this is why a git mv can not help. I provided the links in my original post. – user14202986 Sep 17 '20 at 10:24
  • @user14202986 "All paths, urls and links (except the one with the embedded name) are fine". I really have a hard time determining what "name" is. What do you see? What do you want to see? – VonC Sep 17 '20 at 11:40
  • @user14202986 " It took the name "ltp-html5-authoring" and appends it before everything": append it where? In the working tree? That is part of a *path*, that is what `git mv` would fix. – VonC Sep 17 '20 at 11:42
  • Its the name of the submodule. A folder gets created with the same name. Renaming the folder (and using git mv) causes errors because it does not match the submodule name. When Github renders the web page it is in the form . Im sorry all you can suggest is git mv, that only works on paths, NOT names. I do not know any more ways to explain 'name' so I will just remove the subdomain and re-add it. – user14202986 Sep 17 '20 at 13:45
  • @user14202986 Don't worry, I have a lot of topics at work at the same time I try to understand your issue, that is why I am a bit slow. – VonC Sep 17 '20 at 14:02
  • @user14202986 " https://marvelous-software.github.io/school/ltp-html5-authoring/ltp-html5-authoring"... right, the first `ltp-html5-authoring` could be the name you are talking about. https://github.com/Marvelous-Software/Marvelous-Software.github.io is a User GitHub Pages project. I don't understand why `/ltp-html5-authoring` is repeated twice with a different path in the `.gitmodules` though: https://github.com/Marvelous-Software/Marvelous-Software.github.io/blob/1548092d37a040f0dcf6df5d2370dfd97f55af18/.gitmodules#L2-L9 – VonC Sep 17 '20 at 14:06
  • yes, the first one is exactly what I was talking about. The first is the name and the second is the path. The reason you see things repeated is because I am actively trying to fix it. – user14202986 Sep 17 '20 at 14:11