Specify branch with modules

Is it possible to target a specific branch with a module instead of master.

For example:

[module]

  [[module.imports]]
    path = "github.com/some/repo@test_branch"
1 Like

i tried that. it didn’t work. i hope there’s some trick which would make it…

i can imagine one could use the main branch for assets/ which would serve many websites but then using a custom_branch with small additions for one website out of many.

I think the problem here is, that Hugo builds an HTTPS URL out of that configuration. You could try to force your system to load Github URLs via SSH and see what happens. In SSH-URLs (if we can call them that) it’s possible to tell which branch to use.

Do the following (as I wrote, I did not test loading a branch yet, but for other things it works):

[url "ssh://git@github.com/"]
  insteadOf = https://github.com/

Add this in your ~/.gitconfig or depending on your system where ever your global git configuration lives. This will tell the CLI to use ssh+git instead of HTTP. There was a command-line way to add that, but I don’t remember/find it now.

This is a call in the dark. Not sure if it works, but will test it later today.

Yes, but you cannot specify the branch in config.toml, you need to do it either

  • in go.mod
  • or when “getting” hugo mod get -u github.com/some/repo@someref

I can add to that that it’s really any Git reference (commit, branch, tag), not just branches.

4 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.