Can I version a hugo site with git locally

Hi, I am halfway through with a project. As I am plugging in other people I am starting to worry that I should be able to revert to a previous version if I need to.

Can I make a git repo in my hugo project?

I would run git init in the same directory that contains my config.toml . To avoid potential confusion I have eliminated .git subdirectory from my theme - I am happy with the way theme works and I can fix it if I need to without copying it from themes. Git would track everything in my project, except public/ directory because it is re-generated anew each time.

Does what I want to do seem sensible to the more experienced?


You are on the right track, I think that is what most people do.

My website is here:

You can see the theme is a git submodule and everything else is in the repository (this is not a requirement but that way you can separate your theme and your website).

You could alternatively have your content directory as another git submodule. This way you can keep the main configuration in a separate repository under your control and give other people access to the content repository to add content/pages/etc.


Thanks, your website is very nice too. Clear and informative.

When you say git submodule - what does that mean? I am getting confused around git in main directory and then another for theme (because themes are often obtained/developed via cloning). How does the workflow incorporate submodules and does that mean that the “main” module/part does not touch what is in submodule?

If you really want to feel comfortable you have a solid backup point, simply tar the files up and store them in a safe place.

People always try to make things more complicated. Complicated processes introduce risk.

You can always store the compressed encrypted file on Git if you like. :wink:

1 Like

A git submodule is a like a git repository inside another one. For example, my theme is a git submodule. When I push the code, whatever is in the theme is not stored directly in the website repository. Instead it points to a different git repository instead of saving the contents like a normal directory. If you look at it on Github, you can see that inside my theme/hugo-octopress directory, you can click and it will take you to the theme directory (and a specific commit but do not worry about that).

If it’s something that is slowing you down, do not worry about it, put everything in one git repository and you can revisit later when you are more familiar/comfortable with git.

That is exactly what to do.

~/d/ ❯❯❯ ls -la                                                                               master
total 36
drwxr-xr-x 17 rcogley staff   544 Jan 25 19:54 .
drwxr-xr-x 82 rcogley staff  2624 Feb 13 09:32 ..
drwxr-xr-x 18 rcogley staff   576 Feb 14 08:47 .git
drwxr-xr-x  4 rcogley staff   128 Jan 24 20:33 archetypes
drwx------  6 rcogley staff   192 Jan 29 19:35 content
drwx------  2 rcogley staff    64 Jan 19 23:23 data
drwxr-xr-x  3 rcogley staff    96 Apr 24  2017 i18n
drwxr-xr-x 11 rcogley staff   352 Jan 20 09:15 layouts
drwxrwxr-x 21 rcogley staff   672 Jan 25 19:55 public
drwxr-xr-x  3 rcogley staff    96 Jan 19 23:26 resources
drwxrwxr-x  9 rcogley staff   288 Jan 25 19:55 static
-rw-r--r--  1 rcogley staff 12292 Jan 29 19:44 .DS_Store
-rwxr-xr-x  1 rcogley staff   485 Apr  4  2017 .editorconfig
-rw-r--r--  1 rcogley staff  1192 Apr  4  2017 .gitattributes
-rw-r--r--  1 rcogley staff   782 Jan 17  2018 .gitignore
-rw-r--r--  1 rcogley staff   185 Jan 19 23:05
-rw-------  1 rcogley staff  1388 Jan 25 20:30 config.toml

You can see the .git folder in my hugo project above. That gets made when you do git init. Once you get used to using git, you can next try making an empty repository on a service like github, bitbucket, sourcehut etc., then doing a git push origin master to put your files up there. There are a few steps before you can do that, but there is plenty of info on the internet (e.g. search for the “git book”) on using git.

Many people don’t want to store their generated files in the repository, and if you don’t either, you can put your public folder in a .gitignore file at the root of your project. That way it won’t be committed to your repo.

As for experimentation, once you are used to git a bit more, you can make a “branch” for each experiment. If you make a branch called “new-colors” and switch to it, at first it is just a copy of your master branch. Then you make changes and hugo will just use the files of the branch you are switched to. If you like it, you can “merge” the experimental branch into your master branch.

For now, keep the above points in mind and just try it on a non-critical folder, like a copy of your project folder, as you read through, say, the git book. That way you don’t have to worry about messing anything up badly.

1 Like

Storing files on a repository is a nice thing to know. But, be sure to document and test the entire process including recovery to a previous version. Decide from there if git fits your needs.

I am not trying to dissuade you from using git. It is the standard. But be aware not everyone thinks it’s perfect or easy.

Edited to add an additional “good” reference showing how involving git can become.

1 Like

To argue the “pro git” side of this, you really only need to know a subset of git commands.

In my opinion Atlassian has one of the best git tutorials around. Git Tutorials and Training | Atlassian Git Tutorial


Agreed, that is true, and you’re right about the Atlassian tutorial @zwbetz.

It is in our RRR:

1 Like

Ah, another consideration: having a git repo locally is not a backup. If you push to a service so you have things distributed, it still isn’t really a backup, but it is better than nothing. Besides pushing to github etc, I also am backing up to a couple places. FYI just another thing to consider.

1 Like

Thank you all, it is very good to have various inputs from people with experience. I have already started using git. My goal is to work on it for a little while, then test branching and then I will post a summary here as synopsis and aide-memoire for myself.

Your request is not directly related to Hugo. You should start teaching yourself the basics of Git. An excellent tutorial can be found here: