# Deploy to branch with cli

**URL:** <https://answers.netlify.com/t/deploy-to-branch-with-cli/7445>\
**Category:** Support\
**Tags:** netlify-cli, deployment\
**Created:** [January 14, 2020, 9:51pm UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445 "2020-01-14T21:51:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fabien/32/6057_2.png) [@Fabien](https://answers.netlify.com/u/Fabien)\
**Post date:** [January 14, 2020, 9:51pm UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445/1 "2020-01-14T21:51:09Z")

</div>

Hello!  
I would like to deploy only after my CI tests pass, and I could do it using yarn deploy --site #my\_site\_id --auth #my\_token --prod for the production branch.  
I can’t find a way to do this for the develop and staging branch though.

Right now all I can find is 2 choices:  
1- Set automatic deploys, set branch subdomains and have my code deployed on the correct branch but ignoring my tests  
2- Disable automatic deploys and deploy my code to production after my tests pass, but no develop or staging subdomains.

Can you please tell me if there is a way to deploy programmatically to a specified subdomain (branch)?  
(or a way for Netlify to wait for GitLab CI tests to pass before auto deploying? )

My netlify instance name is: [https://firestar.netlify.com](https://firestar.netlify.com)

---

<div class="post-metadata">

**Author:** ![perry](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/perry/32/16_2.png) [@perry](https://answers.netlify.com/u/perry)\
**Post date:** [January 14, 2020, 11:27pm UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445/2 "2020-01-14T23:27:32Z")

</div>

Hi there,

If I’m understanding your situation correctly, i don’t think this is possible at the moment.

> [@Deploy with CLI to branch](https://answers.netlify.com/t/deploy-with-cli-to-branch/7226):
>
> I’d like to use the Netlify CLI to deploy my site to a specific branch. Is this actually possible?

There is a partial workaround that might work for you written out here:

> [@Build Hooks / Branch Deploy improvements](https://answers.netlify.com/t/build-hooks-branch-deploy-improvements/2566/8):
>
> Hi, thanks for this awesome product! slight_smile Here’s a small feature request: It would be great if you could update the label of a Build Hook instead of deleting and creating a new one!

---

<div class="post-metadata">

**Author:** ![Fabien](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fabien/32/6057_2.png) [@Fabien](https://answers.netlify.com/u/Fabien)\
**Post date:** [January 14, 2020, 11:39pm UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445/3 "2020-01-14T23:39:06Z")

</div>

Thank you for your quick answer!

So basically, to deploy a site on a branch using autodeploy, I would have to either run test locally using a git pre-hook or use netlify CI, am I right?

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [January 21, 2020, 5:37pm UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445/4 "2020-01-21T17:37:27Z")

</div>

You have two options on Netlify CI/CD – automatic deploys (default behavior) triggered by commits to your repository or trigger a deploy using a [build hook](https://docs.netlify.com/configure-builds/build-hooks/#app) in your own CI. Let me know if that answers your question.

---

<div class="post-metadata">

**Author:** ![Fabien](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fabien/32/6057_2.png) [@Fabien](https://answers.netlify.com/u/Fabien)\
**Post date:** [January 24, 2020, 2:38am UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445/5 "2020-01-24T02:38:57Z")

</div>

Thank you Dennis.  
What I was looking for is not currently possible it seems.

We updated our workflow to keep working with Netlify by blocking every push to the develop, master and production branches and allowing only merge requests (we are using GitLab). This way, GitLab will run our tests before they are commited to the branch and prevent a Netlify build to occur.

---

<div class="post-metadata">

**Author:** ![perry](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/perry/32/16_2.png) [@perry](https://answers.netlify.com/u/perry)\
**Post date:** [January 24, 2020, 5:43pm UTC](https://answers.netlify.com/t/deploy-to-branch-with-cli/7445/6 "2020-01-24T17:43:17Z")

</div>

thank you for sharing your solution! This is definitely helpful for other users 👍
