Blog atrasado con gajes del oficio

Errors During Hugo Git

During the last setup of Hugo, I was faced again with the sometimes difficult handling of submodules. This was of course after the corresponding configuration for the user.name and user.email had already been set accordingly.

The next error which dealt with the git submodule was that it already existed in the index. Which made me look it up on Google.

Among the first results that came up after my query, was the following from the stackoverflow site at the StackExchange Network, entitled Issue with adding common code as git submodule: “already exists in the index”

The answer that has been widely accepted included as a solution having to invoke the git rm --cached projectfolder on the tree of the folder.

After issuing it:

 $ git rm --cached .git/public 
 fatal: pathspec '.git/public' did not match any files

Which clearly led me nowhere, I noticed that further implementing correctly the command would require a few more steps.

The command git push origin master indicated that origin did not appear to be a git repository.

 $ git push origin master
 fatal: 'origin' does not appear to be a git repository
 fatal: Could not read from remote repository.

It was only after I invoked the git rm -rf public which seemed to fix the problem:

 $ git rm -rf public/
 Migrating git directory of 'public' from
 '/public/.git' to
 '/.git/modules/public'
 rm 'public'

This seemed to at least tell me that the public folder had been removed. So apparently the --cached flag did nothing in this regard.

Next, by using the <tab> key for autocompletion, right after the directories, I invoked git rm -rf .git/modules, which showed the number of possibilities as shown below:

 $ git rm -rf .git/modules/
 about                        index.html
 config.toml                  index.xml
 config.yaml                  js
 content                      page
 "content                     post
 css                          "post
 deploy.sh                    sitemap.xml
 .gitmodules                  static
 google4417fd3500b3c667.html  "static
 images                       tags
 "images                      themes
 img                          topics

Then again, I completed the git rm -rf with the corresponding public folder:

 $ git rm -rf .git/modules/public/
 fatal: pathspec '.git/modules/public/' did not match any files

Which unfortunately again, came back with the fatal: pathspec error from before.

What worked, was to have the option --cached, to be implemented right after git rm only recursively with the .gitmodules.

So that was

 $ git rm --cached .git
 .git/        .gitmodules  

Which finally after tab completion:

 $ git rm --cached .gitmodules 
 rm '.gitmodules'

So it seems the git rm --cached worked with the .gitmodules, but it did not succeed with the .git/modules/public directory.

It was only after I invoked the Unix command rm -rf under the .git directory, that the problem was finally resolved.

 $ rm -rf .git/modules/public/

After it, the submodule was added again with the

 git submodule add -b master <name of static repository> public

As shown below:

 $ git submodule add -b master https://github.com/<username>/<static repository> public
 Cloning into '/public'...
 remote: Counting objects: 2075, done.
 remote: Compressing objects: 100% (91/91), done.
 remote: Total 2075 (delta 74), reused 114 (delta 31), pack-reused 1907
 Receiving objects: 100% (2075/2075), 4.06 MiB | 2.17 MiB/s, done.
 Resolving deltas: 100% (1247/1247), done.

 $ 

The step-by-step instructions by simply issuing rm -rf public as the tutorial to have Hugo running on Github suggested, did not work in this case, for the simple reason that the git repository was cloned during the initial setup.

The .git/modules/public already existed as a result. So it had to be removed by issuing rm -rf .git/modules/public before setting up again the submodule remote repository.