'One Repository With Multiple Deployments, Environment Variables, and Secrets on Vercel?

I'm doing some early research for a project I plan to deploy to Vercel. I am wondering if the following is possible:

I want to have on GitHub repository. This repository will use environment variables for API tokens, and basic settings.

I have three versions of the project that I want to create. Instead of creating three separate repositories, I'd rather have one repository, and then have the slight differences made using environment variables. This will make updates, fixes, etc much easier.

So, my question is: Is it possible to deploy one repository three times, each with different environment variables, using Vercel?

Solution 1:[1]

Yes, possible in deploying multiple environments in 1 repository. This can be done by importing your project to Vercel. For evey commit you made on the git repo, there is a completely new environment created for that. See https://vercel.com/docs/v2/git-integrations

You may also opt to create different git branches for each environment, and Vercel will take care in creating new environment for them. See https://vercel.com/docs/v2/git-integrations/vercel-for-github#a-deployment-for-each-push

With regards to environment variables, here's what the doc says:

The maximum number of Environment Variables per Environment per Project is 100. For example, you can not have more than 100 Production Environment Variables.

Moreover, the total size of Environment Variables applied to a Deployment (including all the Environment Variables Names and Values) is limited to 4kb. Deployments made with Environment Variables exceeding the 4kb limit will fail during the Build Step. - https://vercel.com/docs/v2/platform/limits?query=environment%20va#environment-variables

Environment Variables: https://vercel.com/docs/v2/build-step#environment-variables

Solution 2:[2]

Yes, they give you Production, Preview, and Development environments. Each has their own environment variables you can save via the UI, or you can download the .env via the cli with vercel env pull.


Vercel environments

Solution 3:[3]

Multiple Vercel projects can be created for the same GitHub repo.

In other words, there is no restriction like only a single Vercel project can be created for the single GitHub repo.

Then, different environment variables can be set for different Vercel projects.

Pushing a commit to the GitHub repo triggers build & deploy of multiple Vercel projects.

Referece: https://github.com/vercel/vercel/discussions/4879#discussioncomment-356114


This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Koleen BP
Solution 2 Rohmer
Solution 3 Tomoyuki Aota