How do I use the Vercel API to deploy private GitHub Repository?

as title states, really nothing else to add.

Hi @rublev1, welcome to the Vercel Community!

Have you tried using the Deployments API with the gitSource property?

Please ensure that your Vercel account is correctly linked to your GitHub account and has access to the said repository.

I hope this helps. Feel free to respond to this thread if you face any issues.

There’s also a CLI available so you can deploy from a local build or use GitHub Actions to deploy from your private repo if you prefer not to link it to your Vercel account for automatic deployments

No. I have been fiddling with the API and all sorts of combinations of fields. I’ve tried all of that.

You cannot deploy a github private repo with the Vercel deployments API.

@amyegan CLI and API are two completely different use cases. Tbh not sure why you’d suggest the CLI in place of the API?

Yes, the CLI and API are obviously different things. :wink: Since you didn’t give a reason for specifically needing an API solution, I wanted to share another option in case it would help you. The CLI has been a preferred solution for other people who did not want to connect a repo with their Vercel account.

Note that you can deploy a private repo with the Vercel API if you connect your Vercel and GitHub accounts and give access for Vercel to deploy from the repo. The Vercel documentation has more info about how to deploy private Git repositories.

The CLI, or a custom workflow using Vercel CLI, is a great option if you are not able to connect your remote repo to your Vercel team. I use it often when deploying examples and testing things.

Ahhhhhhhhhh. So there is currently no way for someone who’s never used vercel to deploy a private repo? For example you login to an app, select a private repo, and then try to push it to vercel to get a deploy URL. I would need to programatically set up a project/team and whatnot, and then do a deploy?

Should my app prompt the user to signup to vercel and follow some series of steps then return to my app before they can do a deploy from my app?

Only reason I’m using vercel is because I can push a repository and it will auto detect the build and return a preview URL. I’m building an app that relies on deploying to vercel to generate a preview and getting a URL back.

So is this possible somehow?

Hi @rublev1, you can deploy private repositories to Vercel, but Vercel needs access to any code that you want to deploy for building and distributing the output on the Edge network.

I’m not sure what you are trying to build, but if you are using Vercel as a deployment for other people’s code, you need to either link their repository to your Vercel account or download their code on your server and use that to deploy. You can use both the API or the CLI for doing so.

If you are providing value on top of the Vercel platform, you may want to explore Vercel Integrations.

It is difficult to provide more help without knowing what is it that you’re trying to solve for your users, but what I’ve shared above is how you can deploy a private repository to Vercel.

1 Like

BRILLIANT thank you, I’ll explore these options:

  • “or download their code on your server and use that to deploy. You can use both the API or the CLI for doing so.”, this is good as i have github integration and code download working. my only concern with this is wouldn’t the project need to be already build before pushing via api? like most frontend repo’s are massive.

It is difficult to provide more help without knowing what is it that you’re trying to solve for your users

use case is simple. user visits my site, logs in with github, selects a repo, selects a branch, clicks “build previews” and it builds a preview for each commit in that branch, and every commit in the future. the user should not care how and where it is being deployed under the hood.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.