Needing two separate netlify.toml files when I only want one

I have another simple 3 page site that uses the single master branch for production which works fine without a netlify.toml. But I am testing on a dummy site some of the more advanced features of working with multiple branches. The instance is: laughing-tereshkova-d11c29

There’s not much there except for an ugly starter template from gatsby, but I did manage to get another branch called ‘stage’ to deploy separately. I can successfully build the two branches separately, but I wanted to play with having different node versions and node packages for each branch using the netlify.toml.

I managed to successfully have each one use a different node version for the production and the stage, but only if I put a netlify.toml in the stage branch root. It seems more logical that the netlify.toml file be in a place where it is recognised by all branches, meaning it should also be seen by the master as well. But if I put the .toml file in ‘master’, then ‘stage’ doesn’t see it.

The directions just say to put it in the ‘base’ or ‘root’ directory of your project, but there are separate base directories for each branch. I must really be missing something that’s obvious here, so I’m preparing myself for embarassment. What am I missing in the instructions?

thanks in advance!!!

Continuing the discussion from Needing two separate netlify.toml files when I only want one:

Welcome @Maloway!

You’ve got the weekend to try different stuff and report back on what you find.

My understanding of the netlify.toml file is that it helps configure the build of a repo.

Does Netlify consider different branches different ‘repos’ ? If so, I could understand what your saying.

I could also understand if a single .toml file was to configure the ‘site’ as it were. I’ll watch this to learn more. :eyes:

Thanks Brian, loving Netlify so far.

Netlify asks you to specify a base directory in your build setings in the dashboard. A Gatsby site can just have blank or just be /. The documentation specifies that ‘To configure deploy contexts, you must create a file called netlify.toml in the root of your Git repository’. But my issue is that each deployment of separate branches sees only the ‘netlify.toml’ file in that branch and not a ‘global’ or master version.

I can test different branches with different node packages without the toml file, but if you want to change the node version or any other env variable for different branches, you would use the netlify.toml. The only way I got this to work was by having one per branch.

Even if I create a different branch for production called ‘prod’ and specify that as the production branch in the dashboard, if I put a global netlify.toml in the repo master, nether ‘prod’ or ‘stage’ will see it.

Anyway it’s not a big deal but I was really just wondering for future reference. I’ve since removed the netflify.toml file from my repo but it would be cool to really understand how this works.

thanks!

1 Like

Hi there,

We clone only the branch that sent us the notification. So yes, we’ll only see the branch-specific netlify.toml file rather than some on another branch; this is by intentional design. So, you must make sure each branch has a correct file for its needs. That is how our system is designed to work. If you need a global setting, you can set it in the UI to apply across all branches, rather than updating netlify.toml in many branches at once.

Ok thanks. I think it was the example netlify.toml at https://docs.netlify.com/configure-builds/file-based-configuration/#sample-file that may have confused me, because looks like a master .toml with settings for different branches, but perhaps it is meant to express the options you would have for each seperate .toml file in each branch. I may have also been confused by the instructions to put it in the base directory of your project, which I suppose could say to put in the base directory of your project branches?
There were a couple of other odd things I noticed though when deploying to my stage branch via a hook. Though I was able to publish them seperately and verify at their different urls, another time Netflify published the stage branch changes and made them visible to the production branch, though I was absolutely certain that ‘master’ did not have those changes. Perhaps that’s a bug or it only happens on the initial deployment of the non-master branch?
thanks!

The example in the docs is a toml intended to be deployed to every branch :slight_smile:

Most folks use the same base directory on every branch of their project, so those instructions say what we meant, but I’ll review this conversation with our documentation team to see if they can come up with an improvement.

I wouldn’t expect any changes not on your production branch to be autopublished, ever. “master” isn’t meaningful here - only the branch you have listed as production in our UI. If you have a reproduction case for that please let me know so I can take a look and get a bug filed if your assertion is true.