Submodules in Github with Hugo
Introduction
I embarked on this journey of using GitHub submodules while setting up my tech blog with Hugo. It was quite the learning curve, but I have managed to grasp the concept fairly well now. For those who are curious, you can check out the repository here: hugo-blog-awesome.
Here, I am jotting down the process I follow to update submodules, especially when I make changes to the files within them. It’s quite a handy note-to-self and perhaps it might assist someone venturing on a similar path.
Updating Submodules in GiHub: Step-by-Step Guide
- Open the Terminal
I usually start by launching my terminal, either the command prompt or Git Bash on Windows.
- Navigate to My Project Directory
Next, use the
cd
command to reach project’s main directory. Like this:
cd path/to/my/project
- Initialize the Submodules If you are working with fresh submodules, you will need to initialize them using this command:
git submodule init
- Update Submodule Then, update the submodule to fetch the latest commits using:
git submodule update
- Navigate to the Submodule Directory Enter the submodule directory, something like:
cd path/to/my/submodule
- Checkout to the Relevant Branch I usually switch to the branch where I want to push the updates, typically it’s the main branch:
git checkout main
- Committing Changes in the Submodule Whenever you make changes within the submodule, please make sure to commit those changes at submodule first:
git add .
git commit -m "Implemented new changes in submodule"
git push
- Returning to the Main Project Directory Then, head back to the main project directory:
cd ..
- Committing and Pushing Changes in the Main Project Lastly, I commit and push the changes in the main project to update the submodule reference:
git add .
git commit -m "Updated submodule with recent changes"
git push
Final Thoughts
This personal guide has been a little savior during my journey of setting up my Hugo tech blog. It might seem a bit overwhelming at first, but with time, it becomes a breeze. Remember, the trick lies in committing changes in the submodule first before updating the main project.
Feel free to explore my Hugo blog repository.