Create a branch deployment of my production branch

Is it possible to create a branch deployment of my production branch?

The use case would be having a deployment running exactly the same code as production, but using branch deployment (non-prod) environment variables.

I’ve noticed I can actually access https://main–[my-netlify-site].netlify.app but that seems to have prod env vars - it seems to be exactly the same deployment as the production one.

Any help appreciated, thanks!

1 Like

Hi, @ruiramos. The only way to do that would be to link the repo to a second site at Netlify and make some other branch the production branch. Then the branch main could be a non-production branch on the second site.

​Please let us know if there are other questions about this.

Hi @luke thanks for getting back to me.

I’d have to manually replicate the environment variables between projects, right? If so, I guess then I wouldn’t necessarily need it to be a branch deploy at that point (could just be the secondary project production with non-prod env vars from the first)

Anyway, is there any way we could suggest this as a feature request? I think it’s probably low hanging fruit and a fairly common use case.

Thanks!

1 Like

I don’t think this will ever make as a feature because this is already possible. Simply create a branch from your production branch, don’t change any content or code and deploy it to Netlify. I don’t see why this needs a whole new feature, unless I’m missing something.

That would work for the initial deployment, but would require that other branch to be kept in sync with “main” manually, so I don’t think this is currently possible, not the way branch deployments work.

I think you’ve got a very weird pipeline - definitely not what I’ve seen or experienced before. Usually, people create a branch from main, push changes to that branch only and when all looks good, create a PR to merge it to main.

No manual syncing is required here.

Sorry if I’m not making myself clear here - this is about having a branch deployment of my production branch (main).

As any other branch deployment, it would be expected to automatically update as new changes are introduced to the code on main.

Your solution of branching off main and deploying that would work for a one shot, but it not automate this process going forward.

The use case is me being able to have the production code deployed with non-prod environment variables - a copy of production linked to a development database, for instance.

Hope this makes it clear!

Hi, @ruiramos. Looking at this thread, it appears that all that remains is that you want us to file a feature request based on this:

What is not clear is this:

  • What feature request do you want us to file?

You also said this:

With that workflow, no one but you knows what the environment variables should be for the new site. What is the part that you want automated? Linking the repo? Naming the site? Setting environment variable?

Please provide as much detail as you can when replying.

Hi @luke. Appreciate your patience with this.

What I’m suggesting as a feature request is the ability to create a branch deployment of your production branch. This would work just like any other branch deployment, namely:

  • it would have a unique “branch” url
  • it would update (build/deploy) whenever the branch gets updated with new commits
  • it would use the env vars specified for branch deployments

The use case is having a separate URL - sorry if this was unclear - where the production/main code is deployed using non-prod environment variables. You could think about this as new staging or qa environment, except I don’t really need a new branch for this - just the production code and non-prod credentials. Hope this makes sense.

I’d suggest we are unlikely to build that, since it is possible to accomplish exactly that using today’s featureset. How?

  1. I’d set up a second site,
  2. set the config up differently (e.g., don’t have your main branch set as production, so it acts more like a branch deploy, or you can set different variables/contexts in the UI if you want it to behave differently),
  3. and then you can have the same effect today, without us implementing anything :slight_smile:
1 Like

Hi @fool ,

Thanks for getting back.

Agree with you this is probably the best way to achieve this today, and probably what I’ll be doing.

Only slight inconvenience is that I’ll be duplicating environment variables across sites, if anything changes I’ll have to remember to update both.

Thanks,
Rui

This approach requires duplicating an entire site and all of it’s config, CI and integrations. I don’t see how that can be seriously seen as equivalent to having this natively.

Furthermore, I think your and Hrishikesh’s responses are rude and patronising, something I’ve noticed before when I have to look up obscure netlify problems on the forums on a weekly basis.

p.s. for anyone else landing on this thread, there are github actions available to keep two branches in sync - bypassing the need to create a separate project

1 Like

The usual Netlify support passive aggressiveness

I’m sorry but where do you see passive aggressiveness in this thread? We try out best to help our customers if you don’t find a solution you are happy to look elsewhere.

Just wanted to add support for this feature request. Our use case: we need to maintain a non-prod branch for generating previews. Using the production branch would mess with our analytics.

@larand, sorry if I’m misunderstanding, but isn’t this what Netlify already offers (and this feature request seems to be different)? You can create a branch deploy from a non-prod deploy.