The Best Gitignore For Hugo?

Dear All

I have this code for my root gitignore files ->

/public/
/resources/_gen/

hugo.exe
hugo.linux
hugo.darwin

But I still curious if it’s the best gitignore or not for Hugo building time process?

Regards

Hi Bayu,

this looks perfect.

I think it has nothing to do with Hugos lightning speed because Hugo just ignores irrelevant files and folders.

This is what I additionally use—where relevant:

.DS_Store
node_modules
dist
tmp

dist is created as some projects require different publishDir. tmp comes from htmltest.

1 Like

Thanks, Grob. By the way, how relevant is adding /public/ into root gitignore file?

The deployed website is located in the folder public. So there is absolutely no need to add this folder to a git repo.

Moreover, the contents of public may change more frequently than the source code, for instance if you make use of the current date. So the suggestion is to keep your repository clean and ignore public.

1 Like

for mac only

Somewhere here I saw the following recommendation:

/public
/resources

(And I have no idea why the preview shows “/public” as boldfaced.)

1 Like

I found a decent one I have been using and added /public to it.

3 Likes

Is it good to includes /public into gitignore for long term use?

One reason to include your generated site would be in case you ever have to manually revert to a specific build of the site. Some people keep the hugo binary for this reason, too. That is to say, “here is the hugo I generated this particular folder with”, as a kind of reproducible evidence.

If you do put your generated site in your repo, be careful you are not including anything that has a password in it. You can put files in a site that are not browsable via a web browser due to server settings and file/folder permissions, and still have them accidentally browsable in a git repo, which is not good.

1 Like

Old topic now but in case anyone experiences the same thing I did I’ll add my input here:

I thought it made sense to add /resources to gitignore but it caused my Netlify build script to fail. It took me a while to figure it out but everything was working perfectly locally but removing /resources from gitignore meant the build script completed successfully again.

I’d be interested to know exactly why that happened but if anyone else has that issue with Netlify then consider this solution.

I might try /resources/_gen, @BayuAngora has this listed in the first post, to see if the build script runs successfully with this as it would save having to push the generated resources files.

I am using this one. The generator has all types of gitignore samples.

https://www.toptal.com/developers/gitignore/api/hugo

2 Likes

I can confirm that setting the gitignore to target the _gen sub directory in resources means the Netlify build is unaffected.

This topic was automatically closed after 3 days. New replies are no longer allowed.