Hi, @chrisjansky. If you need different environment variables for different branches and those environment variables are to be used in functions (both of which appear to be true), then using two sites is the best workaround at this time.
Now, the important thing to understand about how sites are linked to domain names at Netlify is that this is 100% determined by the site settings.
The DNS records only point the domain names to the IP addresses of Netlify’s ADN - nothing more. The DNS records themselves do not determine the site shown in any way at all. After the IP address resolution occurs, the site shown in always 100% determined by the site setting at Netlify (Site Name > Settings > Domain management > Custom domains).
Because you used the branch subdomain for a site and now that site is linked to the branch subdomain until the site is deleted.
The only way to delete a deploy is to delete the site itself. That is the only solution at this time.
What could have happened (but didn’t)
Note: I’m using
example.com in place of the real domain name in these examples.
You could have created a site using the custom domain
example.com and you only used the branch “production” for that site then no branch subdomain would be applied.
Then you could make a second site where the production branch at Netlify was “staging” and add the custom domain
staging.example.com. This is not the branch subdomain feature. You are using a production branch of “staging” and assigning a custom domain.
This allows you to set two different sets of environment variables in the web UI for the two branches.
What actually happened
You made a site and then enabled the branch subdomain feature for it. This permanently links
staging.example.com to this original site.
You have tried to create a new site and assign the branch subdomain to it (
staging.example.com). However, because it is already being used by the site above, this setting doesn’t actually work.
This isn’t a great solution but it is the only solution that exists at this time:
- Delete the original site and then recreate it with all the same setting - except for one. Do not enable the branch subdomains on the newly created site.
This is the only solution because there is no other way to delete deploys at Netlify. Deleting the entire site is the only way do delete a deploy at this time. We cannot just delete the branch deploys because the only way to do so is completely removing the site itself.
So, the only way to delete the branch subdomains enabled for a site is to delete the site itself. If you then recreate the site (same site name
kometa) and link it to the same repo and branch - it will delete all the previous deploys at Netlify.
You will completely lose your deploy history with this solution but it will work. Now the branch subdomain is no longer associated with the new site and the other site using that subdomain as the primary custom domain (not a branch subdomain) will start working.
If there are questions about any of this, please let us know.