# Is it possible to configure Hugo Modules per Git branch in one repository?

**URL:** <https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703>\
**Category:** Uncategorized\
**Created:** [September 13, 2021, 2:16pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703 "2021-09-13T14:16:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkboxomine](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkboxomine](https://discourse.gohugo.io/u/jkboxomine)\
**Post date:** [September 13, 2021, 2:16pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703/1 "2021-09-13T14:16:27Z")

</div>

Hello,

This is a follow-up question to the following thread:

> [@Building content from multiple repositories?](https://discourse.gohugo.io/t/building-content-from-multiple-repositories/34636):
>
> Hello, I’d like to know whether Hugo offers a way to build content from multiple repositories. For example, if content that was once in /content/{subfolder1}, /content/{subfolder2}, … should be moved to separate repositories for each, can we build a site by aggregating content from those repositories? I was not convinced whether [Hugo Modules](https://gohugo.io/hugo-modules/) is fully suitable for this along with our requirements, because of the following: It seems that Hugo Modules do not provide a way to break down the depe…

I verified that Hugo Modules works as @bep’s answer. (Thanks!)

We are managing multiple content repositories, all with a consistent branch scheme (e.g., alpha/beta/production), and need to build sites with aggregated contents per branch.

Is it possible to configure Hugo Modules for each branch in a single repository, similar to what we can do for build configuration? Otherwise, it seems that we must set up separate sites per branch (e.g., project-alpha, project-beta, project-production) with suitable Hugo Modules configuration for each.

---

<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 13, 2021, 3:11pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703/2 "2021-09-13T15:11:15Z")

</div>

> [@jkboxomine](#):
>
> Is it possible to configure Hugo Modules for each branch in a single repository, similar to what we can do for build configuration?

So, you cannot control any versioning from the build configuration. That is stored in `go.mod`, but If I understand you correctly, that should be OK for you. But I may misunderstand.

- You can set up the module configuration in /config/production /config/testing etc. (e.g. what modules to import where)
- Then in each branch (which I assume are Git branches) you can switch versions.

---

<div class="post-metadata">

**Author:** ![jkboxomine](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkboxomine](https://discourse.gohugo.io/u/jkboxomine)\
**Post date:** [September 13, 2021, 3:29pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703/3 "2021-09-13T15:29:55Z")

</div>

> - Then in each branch (which I assume are Git branches) you can switch versions.

I was wondering if it is feasible to manage `go.mod` differently for each branch. Is it OK to run `hugo mod get` with different arguments in each Git branch to set up different versioning per branch? Is the Hugo Modules cache stored per repository or per branch…?

---

<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 13, 2021, 4:01pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703/4 "2021-09-13T16:01:41Z")

</div>

> [@jkboxomine](#):
>
> Is the Hugo Modules cache stored per repository or per branch…?

By default there is one module cache\*\* – but you can mix and match versions in your branches as much as you want, they will live happily side by side in the cache.

\*\* Tip: My approach to this is to have `HUGO_CACHEDIR` environment variable defined to something outside /tmp (which I think is the default), which tends to make it more stable (as in: the cache isn’t removed on reboot).

---

<div class="post-metadata">

**Author:** ![jkboxomine](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@jkboxomine](https://discourse.gohugo.io/u/jkboxomine)\
**Post date:** [September 15, 2021, 10:49am UTC](https://discourse.gohugo.io/t/is-it-possible-to-configure-hugo-modules-per-git-branch-in-one-repository/34703/5 "2021-09-15T10:49:50Z")

</div>

How can we manage the commits for “diverged” `go.mod` (and `go.sum`) in Git branches?

If the situation is like the following:

M: commit on `master` branch for fetching from `master` branch of all content repositories  
A: commit on `alpha` branch for fetching from `alpha` branch of all content repositories  
B: commit on `beta` branch for fetching from `beta` branch of all content repositories  
Cn: Subsequent commits

```auto
main
---- M ----------C1-------C2------
         \
          alpha 
          ---- A -----------------------
         \
          beta
          ---- B -----------------------

```

Can we manage this branching scheme properly without affecting the subsequent commits and merge tasks between branches?

This may be essentially a Git question, but I’d appreciate some word of advice from more experienced users of Hugo.
