Command reference
Working With Git Submodules in Hugo
Additional Updates: 2021-03-15
I’ve been really enjoying Hugo static-site generation. I’ve been customizing it as a book-writing framework, and it’s great!
That said, Hugo likes using git
submodules to manage themes and similar. As a
result of this, when you clone the “main” repo again, your submodules are bare.
One can change this behavior if one remembers, but I’m in such a rut of git clone <url>
that I don’t really think about getting my sub-modules until it’s
too late.
To clone and get submodules: git clone --recurse-submodules <url>
But if you forget…
git submodule update --init # foreach submodule listed in .gitmodules do...
--recursive # git update --init
To fetch latest:
$ cd submodule/path
$ git fetch
$ git reset --hard origin/master # or git checkout -q <origin/master SHA>
To add a new submodule:
$ git submodule add <remote_url> <destination_folder>
And to remove one:
$ git submodule deinit <submodule>
$ git rm <submodule>
References
- Stack Overflow
- I’ve also copied
gitaarik
’s awesome explanation (to save bit rot) after the jump.