TIL: Hugo's GitInfo
Mar 3, 2025While catching up with my RSS feed, I ran into this post by Farid Zakaria which describes how they automatically add the latest git commit hash to their statically generated blog. This gave me the idea to do something similar on my Hugo theme and blog, as I frequently look for a source link when reading other people's blogs.
Hugo has built-in support for this with the GitInfo option. It exports metadata about the commit that last changed a particular page and it automatically updates the last modified date of a post based on the git commit date as well.
To achieve this, I enabled GitInfo on my Hugo configuration and then updated my theme to add support for this feature at the bottom of every post. Now, there's an extra link at the end of each post that takes you to the source of the last commit for this file. You should be seeing this at the end of this page ;)
Tags: til log hugoSource: GitHub