# Mounting different branches/tags from the same repository

**URL:** <https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849>\
**Category:** support\
**Created:** [September 4, 2025, 11:59am UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849 "2025-09-04T11:59:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [September 4, 2025, 11:59am UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/1 "2025-09-04T11:59:16Z")

</div>

In my main repository (where I build Hugo) I am using module imports to pull in documentation (for an API) written in another remote repository. The documentation in the other repository is organised in a simple way, like this:

```auto
docs
--file1.md
--file2.md
--folder
----file1.md
----file2.md

```

The currently unreleased documentation in this “remote” repository is in “master” and already released dev is stored in a branch with a name that corresponds to the version of the API (i.e. “v3.4.0”). There are no version numbers in the “docs” folder.

I am specifying the “v3.4.0” branch of this remote repository in the `go.mod` file of my main repository, by using `hugo mod get -u https://gitlab.com/org/repo.git@v3.4.x`, this translates to a specific commit hash relating to that branch in the `go.mod` file.

Then, in `hugo.toml`, I use `module.imports` to specify the repository (without a branch name) and then `module.imports.mount` to mount the content of the “docs” folder where I need it, i.e. in a folder called “3.4”, like this:

```auto
  [[module.imports]]
    path="gitlab.com/org/repo"
  [[module.imports.mounts]]
    source = "docs"
    target = "content/api/3.4"

```

So, when the next release of this API doc is ready, in the remote repository it will be put in a branch called “v3.5.0” (for example). Then I will have a branch called “v3.4.0” and “v3.5.0”. I would then like to be able to pull in the files in the “v3.5.0” branch and mount them in my main doc repository in a folder called “3.5” (as well as pulling in the files in the v3.4.0 branch and putting them in a folder called “3.4”).

However, I cannot find a way to do this and I am unsure it is even possible. I had thought about specifying each branch in `go.mod` but that doesn’t work as `hugo mod get` just overwrites the entry for the repository instead of appending an additional one. It looks like you can only specify a repository once in `go.mod`. And it seems it’s not possible to specify branches in `mount.imports` either.

The only way I could see this working is to create the 3.4 and 3.5 folders in the remote repository and mount them via `hugo.toml`, but I’m trying to avoid doing that.

Are there any other options within Hugo that would allow me to do what I am trying to do?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 4, 2025, 4:31pm UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/2 "2025-09-04T16:31:23Z")

</div>

> <https://github.com/gohugoio/hugo/issues/13964>
>
> See https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same…-repository/55849
> 
> That discussion isn't new, and looking at it in the light of the upcoming new version and role dimensions in Hugo (in addition to the existing language), having a way to mount multiple minor versions of a module in the same project would be supe useful.
> 
> I have certainly spent some time thinking about this before, but I suspect I haven't thought "simple" enough.
> 
> So, Go Modules support multiple major versions of the same module (e.g. \`github.com/bep/mymod\` and \`github.com/bep/mymod/v2\`), but I don't think there's a practical way to do multiple minor versions directly with Go Modules.
> 
> But I think we could add a concept of fixed version module imports (with a commit hash or a version tag added to the config), so we get:
> 
> 1. A set of module imports that follows the version life cycle of Go Modules (with Minimum Version Selection (MVS) and version upgrades via \`hugo mod get\` etc.). This is typically the current working branch of content modules you're working on, shortcode/JavaScript/CSS modules etc.
> 2. A set of module imports with a fixed version set in \`hugo.toml\`. These will not show up in \`go.mod\` or \`go.sum\` (we probably need to add a \`hugo.sum\` for these), and they will not be upgradable via \`hugo mod get\`(you need to edit the config), but other than that they should work as the "others".
> 
> I will spend a couple of hours tomorrow morning (when my head is fresh) to see if the above is viable.

---

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [September 4, 2025, 4:36pm UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/3 "2025-09-04T16:36:16Z")

</div>

Wow, thank you. I didn’t expect that, I will follow with interest.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 5, 2025, 9:38am UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/4 "2025-09-05T09:38:25Z")

</div>

Getting the first working version up and running was surprisingly straight forward – and it works pretty good in my tests. There are some missing pieces to get this over the finish line, but it should not take too long:

> <https://github.com/gohugoio/hugo/pull/13966>
>
> Fixes #13964
> 
> \## Notes
> 
> \* \`version\` can be blank or set to a Go Module \[vers…ion query\](https://go.dev/ref/mod#version-queries)
> \* If \`version\` has a value, you don't need a \`go.mod\` file unless there's a transitive dependency without a defined \`version\`. You can work around this by \[ignoring any imports\](https://gohugo.io/configuration/module/#ignoreimports) on the module you import.
> \* You can import the same \`path\` multiple times with different values of \`version\`, but you need to think about how to mount the different versions into your project. Also see the \[nomounts\](https://gohugo.io/configuration/module/#nomounts) config setting.
> \* The command \`hugo mod get\` will only work on module imports without a \`version\` set, so for these you either need to edit the config file or set a loose \[version query\](https://go.dev/ref/mod#version-queries) (e.g. \`main\`, \`latest\`, \`\>v1.0.0\`) . Note that Go Module's Minimum Version Selection (MVS) is not relevant for these imports.
> 
> 
> \## TODOs
> 
> \- \[\] vendoring with \`hugo mod vendor\`. I think putting the different vendored version below \`\_vendor/\_versions\` would work.
> \- \[\] \`go.sum\`; imports with \`version\` set will not en up in \`go.{mod,sum}\`. The first can be a good thing (because you don't need a \`go.mod\` file for simpler setups). But without a \`sum\` entry, we don't get the security it gives, which I think is worth going the extra mile. I think that the tooling for this should be relatively straight forward and that we could create an extra \`hugo.sum\` file for these entries).

---

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [September 5, 2025, 10:13am UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/5 "2025-09-05T10:13:34Z")

</div>

Again that is amazing! Thank you for your efforts…!

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 8, 2025, 6:57pm UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/6 "2025-09-08T18:57:15Z")

</div>

> **[Release v0.150.0 · gohugoio/hugo](https://github.com/gohugoio/hugo/releases/tag/v0.150.0)**
>
> The big new feature in this relase is the new version config option on Module imports, which allows you to set the requested module version query directly in your Hugo configuration (e.g. hugo.toml...

---

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [September 8, 2025, 7:04pm UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/7 "2025-09-08T19:04:40Z")

</div>

Oh gosh that was quick - thank you so much - really appreciate the blazing fast turn around (as quick as Hugo builds!!).

I’ll be upgrading from 0.147.5 to 0.150.0 tomorrow. It will be used here if you’re interested: [Imaging API v3 | Documentation](https://doc.castsoftware.com/imaging-api/)

---

<div class="post-metadata">

**Author:** ![jimmyhurr](https://avatars.discourse-cdn.com/v4/letter/j/5f9b8f/32.png) [@jimmyhurr](https://discourse.gohugo.io/u/jimmyhurr)\
**Post date:** [September 9, 2025, 9:25am UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/8 "2025-09-09T09:25:00Z")

</div>

Well, hat’s off to you @bep it works flawlessly and is so easy to configure.

**hugo.toml:**

```auto
  [[module.imports]]
    path="gitlab.com/castdoc/imaging-api"
    version="v3.4.x"
  [[module.imports.mounts]]
    source = "docs"
    target = "content/api-test/3.4"
  [[module.imports]]
    path="gitlab.com/castdoc/imaging-api"
    version="master"
  [[module.imports.mounts]]
    source = "docs"
    target = "content/api-test/3.5"

```

Built with Cloudflare: [Imaging API - 3.4 | Documentation](https://jhu-imaging-api-auto.doc-6ly.pages.dev/api-test/3.5/) (I just need to bump the version number for the 3.5 files from 3.4 to 3.5)…

Brilliant! Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 11, 2025, 9:25am UTC](https://discourse.gohugo.io/t/mounting-different-branches-tags-from-the-same-repository/55849/9 "2025-09-11T09:25:56Z")

</div>

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