Cloudflare pages Staging setup? using same repo

Hi there,

Reading this post by Cloudflare where i can setup a staging domain but at this moment i can only use a repo once and for the staging site i need to create an aditional repo and connect it to the new pages(staging site) why cant i have a repo - pulling form main branch & - pulling from staging branch of the same repo

it sounds stupid to and not at all easy to have the limitation of only being using 1 repo for pages site there is a thing called brances in git is Cloudflare aware of that :stuck_out_tongue: just kidding i know you know what brances are but why dont you let us use a repo twice and simply use different branch or provide a default option of live and staging for pages environment


You don’t need two projects for this. You can get a staging and production domain from your one project -

Hi @Walshy

I think you misunderstood me what i am saying is when i create a pages site i can only use a repo once that means i can only select 1 branch and that means to create a staging site i need to first create a new repo and connect it to Cloudflare to make the staging site. or it has been changed?



You don’t select a specific branch to build. We can build the site for all branches and we also provide a way to create a custom domain for all branches. See the link I sent. This has always been the case.

Lots of our users have a staging and production domain.

Hi @Walshy

I didnt knew Cloudflare build sites for all branches is there a link where i show more on how that works i am not worried about custom domains.

So if my repo have 2 branches main and staging Cloudflare ask me to choose a branch when i connect a repo and after that there is no option to reselect the same repo with different branch or a way to see the sites created using 2nd branch?

Am i the only one lost here on how pages and branches work? a guide on how to access the different sites built from different branches will be really helpfull

thank you for taking the time


Where are you seeing this branch selection? I’m guessing you’re using direct uploads? If so, that’s just the production branch name. You can still publish other branches just fine and use them as normal.

There is no branch selection if you aren’t using direct uploads, we just start to build your site when we get pushes from GitHub/GitLab.

Hi @Walshy

As Cloudflare pages were really slow taking almost 10-15 minutes for each build of a hugo site which only needs a few miliseconds to build. what i did is prebuilt site locally and then push the site to a repo ready to be copied as it is. So yes i am using prebuilt option but in the repo i can still have multiple branches.

Can i have 2 sites built from 2 branches while using prebuilt option in Cloudflare pages


Ok, so yep you can just publish other branches the same way you publish production and you’ll have your site available there too. So, say you push changes to staging, you’d then run wrangler pages publish <dir> on that branch. You can then access the site at staging.<project> (and also add that to your custom domain).

hi @Walshy

where do i run wrangler pages publish <dir> is this a code i need to add somehwere on Cloudflare or on GitHub?


You would run that as part of your Continuous Deployment pipeline (that may be on GitHub or Jenkins or CircleCI or elsewhere)

Hi @Walshy

I’m trying to get the following setup:

  • any branch other than “master” should build the preview, which is protected via Cloudflare Access
  • “master” branch should build staging version of the app, and still be protected via Cloudflare Access
  • manual Webhook request should build production version of the app and be available publically

The reason is that I want to ship features quick, and my pipeline includes “manual approve” for each CI Pipeline, that normally triggers production deployment from the same branch once already verified that staging works fine.

I got 1st and 3rd point working as expected, but I can’t get the actual staging without introducing another branch and having to merge staging to production every time I want to do deploy my changes. Am I missing something maybe?


The usual workflow is that your master branch is the production site, and the way you build and deploy it is to merge into that branch. So you propose a production build by creating a pull request, which builds a preview deployment from that branch and can require manual approval to merge to the master branch. The approval causes the merge which then pushes to production.

Any branch other than your master branch (whatever branch that is) can create a preview build (or not, as per your settings). If you want a designated staging branch you can have one, with a custom domain pointing to it.

I understand that the branches are tied to environment deployment in Cloudflare today.

It’d be nice to have a support for @msajnog93 request, I was stalk with same issue while trying to setup a manual production deploy from the main branch.

I didn’t like the 2 seperate branches approach for staging and production deployment… I want to auto deploy to staging for every merge to main and then trigger a manual deploy to production with deploy hook

A quick way to help with this issue is to provide a fixed alias for preview branches, so I don’t keep getting different urls. cc: @Walshy

You can have a fixed alias for the latest preview deployment now. Just add another custom domain, like, to the project. Go to your DNS settings and change the CNAME that was automatically added to point to the branch alias instead of production.

Thanks for your response @i40west

I just checked on the docs now and discovered the feature is only available on Cloudflare DNS

I currently use an external provider :frowning: