Using git to manage a Hugo site?

Three years ago I asked about managing Hugo from two separate systems, one Linux, one Windows. The advice given there was: use git. And in fact I never did, I just kept on using my Linux system for all my Hugo needs. But these days I find myself more in Windows than Linux … and so I will have to set up a git repo and use it. I appreciate the power of git, but my past experiences have been painful - I’ve only learned enough to be stupid; I’ve never had the time or reason to learn it properly.

So what I’m hoping for is a simple intro to using Hugo with git. I’m assuming that on what ever machine I’m on it would be a matter of git pull, make changes, git add (new files), git commit, git push … but maybe there’s more to it that that? I also need to know what to put in .gitignore - I’ve seen public listed here, but I don’t know why. Also maybe themes (given that they are repos themselves)?

Many thanks!

You can read any getting started guide for git. There is nothing special about using git with Hugo.

The .gitignore files should contain public/. You can quickly regenerate it but just running the hugo command so it is just a hassel to have under version control.

Some prefer to put resources/ in .gitignore as well. The “resources” directory contains the build cache. For small simple sites the cache will cut some seconds of your build time, but for larger site with many images it can save substantial time. So it is up to you.

1 Like

If you are making a git repo that you will be accessing and updating from both Windows and Linux you will probably want to do some reading about line ending issues. This was wisdom I bookmarked over a decade ago; no doubt there is more recent wisdom you will find but that might get you started with an awareness of the issues (which are by no means Hugo specific.) I’m no longer on Windows so can’t provide more specific advice.

1 Like

Thanks! A bigger issue for me has been that Windows file names are case insensitive, unlike Linux. The main problem here are files which are automatically generated.

You might want to explore the use of git-config’s core.ignoreCase option – although a quick web search suggests there are some potential issues lurking there.

I am more skeptical of why the pattern(s) for automatically generated files would not simply be added to .gitignore and let caches maintain themselves on each system. I assume builds on each OS produce reproducible, if not identical content. But maybe I am misunderstanding something.

Just to say - I maintain several sites (not very complex) exactly this way. I sync them via home git server (simply read https://git-scm.com/book/en/v2/Git-on-the-Server-Getting-Git-on-a-Server) so that I can add to the site either on my linux laptop that I mostly use at home, or my windows laptop issued by my work. I tend to push from linux only via rsync. I keep resources/ and public/ in .gitignore as suggested above. I like the setup and the ease of pushing with an oneliner hugo && rsync....