|
1 | 1 | ---
|
2 |
| -title: Deploy from a Local Git Repository |
3 |
| -description: Learn how to enable local Git deployment to Azure App Service. One of the simplest ways to deploy code is from your local computer. |
| 2 | +title: Deploy From a Local Git Repository |
| 3 | +description: Learn how to configure and carry out local Git deployment to Azure App Service. |
4 | 4 | ms.topic: how-to
|
5 |
| -ms.date: 02/29/2024 |
| 5 | +ms.date: 06/24/2025 |
6 | 6 | ms.reviewer: dariac
|
7 | 7 | ms.custom: devx-track-azurecli, devx-track-azurepowershell
|
8 | 8 | author: cephalin
|
9 | 9 | ms.author: cephalin
|
10 | 10 | ---
|
11 |
| -# Deploy to Azure App Service by using Git locally |
| 11 | +# Deploy to Azure App Service by using local Git |
12 | 12 |
|
13 |
| -This article shows you how to deploy your app to [Azure App Service](overview.md) from a Git repository on your local computer. |
| 13 | +One of the simplest ways to deploy code is from your local computer. This article shows you how to deploy your app to [Azure App Service](overview.md) from a Git repository on your local computer. |
14 | 14 |
|
15 | 15 | > [!NOTE]
|
16 |
| -> This deployment method requires [Source Control Manager (SCM) basic authentication](configure-basic-auth-disable.md), which is less secure than [other deployment methods](deploy-authentication-types.md). If local Git deployment doesn't work, you can't configure local Git deployment in the app Deployment Center. |
| 16 | +> Local Git deployment requires [Source Control Manager (SCM) basic authentication](deploy-configure-credentials.md), which is less secure than [other deployment methods](deploy-authentication-types.md). If [basic authentication is disabled]((configure-basic-auth-disable.md)), you can't configure local Git deployment in the app Deployment Center. |
17 | 17 |
|
18 | 18 | ## Prerequisites
|
19 | 19 |
|
20 |
| -To complete the steps that are described in this article: |
| 20 | +To complete the steps in this article: |
21 | 21 |
|
22 | 22 | - [!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)]
|
23 | 23 |
|
24 |
| -- [Install Git](https://www.git-scm.com/downloads). |
| 24 | +- [Install Git](https://www.git-scm.com/downloads), and have a local Git repository with code to deploy. |
25 | 25 |
|
26 |
| -- Have a local Git repository with code to deploy. To download a sample repository, run the following command in your local terminal window: |
| 26 | + To clone a sample repository, run the following command in your local terminal window: |
27 | 27 |
|
28 | 28 | ```bash
|
29 | 29 | git clone https://github.com/Azure-Samples/nodejs-docs-hello-world.git
|
30 | 30 | ```
|
31 | 31 |
|
32 |
| -[!INCLUDE [Prepare repository](../../includes/app-service-deploy-prepare-repo.md)] |
| 32 | +- Configure a deployment user. You can use either [user-scope](deploy-configure-credentials.md#userscope) or [application-scope](deploy-configure-credentials.md#appscope) credentials to deploy your app. |
33 | 33 |
|
34 |
| -## Configure a deployment user |
| 34 | + - To configure a *user-scope deployment user* by using the Azure portal or Azure CLI, follow the instructions at [Configure user-scope credentials](#deploy-configure-credentials.md#userscope). You only need a user name, not a password, to create a local Git deployment user. The deployment user name is different from your Azure account user name. You can use the same App Service deployment user for all the apps in your Azure subscription. |
| 35 | + - An *application-scope user* is app-specific and is created automatically when you create an app. You can get the application-scope user credentials from the **Local Git/FTPS credentials** tab in the **Deployment Center** for your app. |
35 | 36 |
|
36 |
| -Learn how to [configure deployment credentials for Azure App Service](deploy-configure-credentials.md). You can use either user-scope sign-in information or application-scope sign-in information. |
| 37 | +[!INCLUDE [Prepare repository](../../includes/app-service-deploy-prepare-repo.md)] |
37 | 38 |
|
38 |
| -## Create a Git-enabled app |
| 39 | +## Create and configure a Git-enabled app |
39 | 40 |
|
40 |
| -If you already have an App Service app and you want to configure a local Git deployment for the app, see [Configure an existing app](#configure-an-existing-app) instead. |
| 41 | +You can create and configure a Git-enabled app by using Azure CLI, Azure PowerShell, or the Azure portal. |
41 | 42 |
|
42 | 43 | # [Azure CLI](#tab/cli)
|
43 | 44 |
|
44 |
| -Run [az webapp create](/cli/azure/webapp#az-webapp-create) with the `--deployment-local-git` option. |
45 |
| - |
46 |
| -For example: |
47 |
| - |
48 |
| -```azurecli |
49 |
| -az webapp create --resource-group <group-name> --plan <plan-name> --name <app-name> --runtime "<runtime-flag>" --deployment-local-git |
50 |
| -``` |
51 |
| - |
52 |
| -The output contains a URL like the example `https://<deployment-username>@<app-name>.scm.azurewebsites.net/<app-name>.git`. Use this URL to deploy your app in the next step. |
53 |
| - |
54 |
| -# [Azure PowerShell](#tab/powershell) |
55 |
| - |
56 |
| -Run [New-AzWebApp](/powershell/module/az.websites/new-azwebapp) from the root of your Git repository. |
57 |
| - |
58 |
| -For example: |
59 |
| - |
60 |
| -```azurepowershell |
61 |
| -New-AzWebApp -Name <app-name> |
62 |
| -``` |
63 |
| - |
64 |
| -When your run this cmdlet from a directory that's a Git repository, a Git remote named `azure` for your App Service app is automatically created. |
65 |
| - |
66 |
| -# [Azure portal](#tab/portal) |
67 |
| - |
68 |
| -In the portal, create an app first. Then, set up deployment for the app. For more information, see [Configure an existing app](#configure-an-existing-app). |
69 |
| - |
70 |
| ------ |
71 |
| - |
72 |
| -## Configure an existing app |
| 45 | +- To create a new web app configured for local Git deployment, run [az webapp create](/cli/azure/webapp#az-webapp-create) with the `--deployment-local-git` option. For example: |
73 | 46 |
|
74 |
| -If you don't have an app yet, get started with [Create a Git enabled app](#create-a-git-enabled-app). |
| 47 | + ```azurecli |
| 48 | + az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name myApp --runtime "NODE:20-lts" --deployment-local-git |
| 49 | + ``` |
75 | 50 |
|
76 |
| -# [Azure CLI](#tab/cli) |
| 51 | +- To configure local Git deployment for an already-existing app, run [az webapp deployment source config-local-git](/cli/azure/webapp/deployment/source#az-webapp-deployment-source-config-local-git). For example: |
77 | 52 |
|
78 |
| -Run [az webapp deployment source config-local-git](/cli/azure/webapp/deployment/source#az-webapp-deployment-source-config-local-git). |
| 53 | + ```azurecli |
| 54 | + az webapp deployment source config-local-git --name myApp --resource-group myResourceGroup |
| 55 | + ``` |
79 | 56 |
|
80 |
| -For example: |
| 57 | +Either command produces output that includes a URL, such as: |
81 | 58 |
|
82 |
| -```azurecli |
83 |
| -az webapp deployment source config-local-git --name <app-name> --resource-group <group-name> |
| 59 | +```output |
| 60 | +Local git is configured with url of 'https://[email protected]/myApp.git' |
84 | 61 | ```
|
| 62 | +The URL contains the user-scope deployment user name. If there's no user-scope deployment user name, the URL for the app uses the [application-scope user name ](deploy-configure-credentials.md#appscope), for example `https://[email protected]/myApp.git`. Use this URL to deploy your app in the next step. |
85 | 63 |
|
86 |
| -The output contains a URL like the example `https://<deployment-username>@<app-name>.scm.azurewebsites.net/<app-name>.git`. Use this URL to deploy your app in the next step. |
| 64 | +# [Azure PowerShell](#tab/powershell) |
87 | 65 |
|
88 |
| -> [!TIP] |
89 |
| -> This URL contains the user-scope deployment username. You can [use application-scope sign-in information](deploy-configure-credentials.md#appscope) instead. |
| 66 | +1. Run [New-AzWebApp](/powershell/module/az.websites/new-azwebapp) from the root of your cloned Git repository. For example: |
90 | 67 |
|
91 |
| -# [Azure PowerShell](#tab/powershell) |
| 68 | + ```azurepowershell |
| 69 | + New-AzWebApp -Name myApp |
| 70 | + ``` |
92 | 71 |
|
93 |
| -Set the `scmType` of your app by running the [Set-AzResource](/powershell/module/az.resources/set-azresource) cmdlet. |
| 72 | + When you run this cmdlet from a directory that's a Git repository, it automatically creates a Git remote repository named `azure` for your App Service app. |
94 | 73 |
|
95 |
| -```azurepowershell |
96 |
| -$PropertiesObject = @{ |
97 |
| - scmType = "LocalGit"; |
98 |
| -} |
| 74 | +1. Set the `scmType` of your app by running the [Set-AzResource](/powershell/module/az.resources/set-azresource) cmdlet. |
99 | 75 |
|
100 |
| -Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName <group-name> ` |
101 |
| --ResourceType Microsoft.Web/sites/config -ResourceName <app-name>/web ` |
102 |
| --ApiVersion 2015-08-01 -Force |
103 |
| -``` |
| 76 | + ```azurepowershell |
| 77 | + $PropertiesObject = @{ |
| 78 | + scmType = "LocalGit"; |
| 79 | + } |
| 80 | + |
| 81 | + Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName <group-name> ` |
| 82 | + -ResourceType Microsoft.Web/sites/config -ResourceName <app-name>/web ` |
| 83 | + -ApiVersion 2015-08-01 -Force |
| 84 | + ``` |
104 | 85 |
|
105 | 86 | # [Azure portal](#tab/portal)
|
106 | 87 |
|
107 |
| -1. In the [Azure portal](https://portal.azure.com), go to your app. |
108 |
| - |
109 |
| -1. On the resource menu, select **Deployment Center** > **Settings**. |
110 |
| -1. For **Source**, select **Local Git**, and then select **Save**. |
| 88 | +1. In the [Azure portal](https://portal.azure.com), create an App Service app by following any of the portal-based instructions under **Create your first app** at [Getting started with Azure App Service](getting-started.md). On the **Deployment** tab of the app creation screen, make sure to set **Basic Authentication** to **Enabled**. |
| 89 | +1. When the app is created, select **Go to resource**. |
| 90 | +1. Select **Deployment Center** under **Deployment** in the left navigation menu for the app. |
| 91 | +1. On the **Settings** tab, select **Local Git** from the dropdown list next to **Source**, and then select **Save**. |
111 | 92 |
|
112 | 93 | :::image type="content" source="media/deploy-local-git/enable-portal.png" alt-text="Screenshot that shows how to enable local Git deployment for App Service in the Azure portal.":::
|
113 | 94 |
|
114 |
| -1. In the **Local Git** section, copy the value for **Git Clone Uri** to use later. This URI doesn't contain any sign-in information. |
| 95 | +1. The **Git clone URI** appears under **Local Git** on the **Settings** screen. This URI doesn't contain any sign-in information. Copy the value to use in the next step. |
| 96 | + |
| 97 | +If you already have an app to use, you can configure local Git deployment from the **Settings** tab of the app's **Deployment Center**. Copy the deployment URI. |
115 | 98 |
|
116 | 99 | -----
|
117 | 100 |
|
118 | 101 | ## Deploy the web app
|
119 | 102 |
|
120 |
| -1. In a local terminal window, change the directory to the root of your Git repository. Add a Git remote by using the URL from your app. If the method you use doesn't provide a URL, use `https://<app-name>.scm.azurewebsites.net/<app-name>.git` with your app name. |
| 103 | +1. In a local Bash terminal window, change directory to the root of your cloned Git repository. |
| 104 | +1. Add a Git remote by using the URL returned from configuring your app. |
| 105 | + - If you used Azure PowerShell`New-AzWebApp` to create the app, the remote is already created. |
| 106 | + - If the method you used didn't provide a URL, use `https://<app-name>.scm.azurewebsites.net/<app-name>.git` for the URL. |
121 | 107 |
|
122 | 108 | ```bash
|
123 | 109 | git remote add azure <url>
|
124 | 110 | ```
|
125 | 111 |
|
126 |
| - > [!NOTE] |
127 |
| - > If you [created a Git-enabled app in PowerShell by using New-AzWebApp](#create-a-git-enabled-app), the remote is already created. |
128 |
| -
|
129 |
| -1. Push to the Azure remote branch by running `git push azure master`. |
130 |
| - |
131 |
| - For more information, see [Change the deployment branch](#change-the-deployment-branch). |
132 |
| - |
133 |
| -1. In the **Git Credential Manager** dialog, enter your [user-scope or application-scope sign-in information](#configure-a-deployment-user), not your Azure sign-in information. |
134 |
| - |
135 |
| - If your Git remote URL already contains your username and password, you aren't prompted to enter them. |
136 |
| - |
137 |
| -1. Review the output. You might see runtime-specific automation, such as MSBuild for ASP.NET, npm install for Node.js, or pip install for Python. |
138 |
| - |
139 |
| -1. In the Azure portal, go to your app to verify that the content is deployed. |
| 112 | +1. Push to the Azure remote branch by running `git push azure main`. |
| 113 | +1. If the **Git Credential Manager** dialog appears, enter your user-scope deployment user name or application-scope sign-in information. If your Git remote URL already contains the sign-in information, you aren't prompted to enter it. |
| 114 | +1. Review the output. You might see runtime-specific automation, such as `MSBuild` for ASP.NET, `npm install` for Node.js, or `pip install` for Python. |
| 115 | +1. If you get errors, see [Troubleshoot deployment](#troubleshoot-deployment) or [Change the deployment branch](#change-the-deployment-branch). |
| 116 | +1. In the Azure portal, verify that the app deployed successfully by selecting the **Default domain** link on the app's **Overview** page. The app should open in a browser tab and display **Hello World!**. |
140 | 117 |
|
141 | 118 | <a name="change-deployment-branch"></a>
|
142 |
| - |
143 | 119 | ## Change the deployment branch
|
144 | 120 |
|
145 |
| -When you push commits to your App Service repository, App Service deploys the files in the `master` branch by default. Because many Git repositories are moving from `master` to `main`, ensure that you push to the correct branch in the App Service repository in one of two ways: |
| 121 | +When you push commits to your `azure` App Service repository, App Service deploys the files in the `master` branch by default. Many Git repositories, including the sample code repository for this article, use `main` as the default branch. You must ensure that you push to the correct branch in the App Service repository by taking one of the following steps: |
146 | 122 |
|
147 |
| -- Explicitly deploy to `master` by running a command like in this example: |
| 123 | +- Explicitly deploy to `master` instead of `main` by using the following `push` command: |
148 | 124 |
|
149 | 125 | ```bash
|
150 | 126 | git push azure main:master
|
151 | 127 | ```
|
152 | 128 |
|
153 |
| -- Change the deployment branch by setting the `DEPLOYMENT_BRANCH` app setting, and then push commits to the custom branch. |
| 129 | +- Change the `DEPLOYMENT_BRANCH` app setting to `main`, and then push the commit to `main`. |
154 | 130 |
|
155 |
| - To do it by using the Azure CLI: |
| 131 | + - Azure CLI: |
156 | 132 |
|
157 | 133 | ```azurecli
|
158 | 134 | az webapp config appsettings set --name <app-name> --resource-group <group-name> --settings DEPLOYMENT_BRANCH='main'
|
159 | 135 | git push azure main
|
160 | 136 | ```
|
161 | 137 |
|
162 |
| - You can also change the `DEPLOYMENT_BRANCH` app setting in the Azure portal: |
| 138 | + Azure portal: |
163 | 139 |
|
164 |
| - 1. Under **Settings**, select **Environment variables**. |
165 |
| - 1. Add an app setting that has the name `DEPLOYMENT_BRANCH` and the value `main`. |
| 140 | + 1. On the portal page for your app, select **Environment variables** under **Settings** in the left navigation menu. |
| 141 | + 1. On the **Environmental variables** page, select **Add**. |
| 142 | + 1. On the **Add/edit application setting** screen, enter *DEPLOYMENT_BRANCH* for **Name** and *main* for **Value**, and then select **Apply**. |
| 143 | + 1. In the Bash terminal, run `git push azure main`. |
166 | 144 |
|
167 | 145 | ## Troubleshoot deployment
|
168 | 146 |
|
169 |
| -You might see the following common error messages when you use Git to publish to an App Service app in Azure: |
| 147 | +The following common errors might occur when you use local Git to publish to an App Service app in Azure: |
170 | 148 |
|
171 | 149 | |Message|Cause|Resolution|
|
172 | 150 | |---|---|---|
|
173 | 151 | |`Unable to access '[siteURL]': Failed to connect to [scmAddress]`|The app isn't running.|In the Azure portal, start the app. Git deployment isn't available when the web app is stopped.|
|
174 |
| -|`Couldn't resolve host 'hostname'`|The address information for the `azure` remote is incorrect.|Use the `git remote -v` command to list all remotes and their associated URLs. Verify that the URL for the `azure` remote is correct. If needed, remove and and then re-create this remote by using the correct URL.| |
175 |
| -|`No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'main'.`|You didn't specify a branch when you ran `git push` or you haven't set the `push.default` value in `.gitconfig`.|Run `git push` again, and specify the main branch: `git push azure main`.| |
176 |
| -|`Error - Changes committed to remote repository but deployment to website failed.`|You pushed a local branch that doesn't match the app deployment branch on `azure`.|Verify that the current branch is `master`. To change the default branch, use the `DEPLOYMENT_BRANCH` application setting. For more information, see [Change deployment branch](#change-the-deployment-branch). | |
177 |
| -|`src refspec [branchname] does not match any.`|You tried to push to a branch other than `main` on the `azure` remote.|Run `git push` again, and specify the main branch: `git push azure main`.| |
178 |
| -|`RPC failed; result=22, HTTP code = 5xx.`|This error might occur if you try to push a large git repository over HTTPS.|Change the git configuration on the local computer to set a higher value for `postBuffer`. For example: `git config --global http.postBuffer 524288000`.| |
179 |
| -|`Error - Changes committed to remote repository but your web app not updated.`|You deployed a Node.js app with a _package.json_ file that specifies additional required modules.|Review the `npm ERR!` error messages that appear before this error for more context. The following causes are known causes of this error and the corresponding `npm ERR!` messages:<br /><br />**Malformed package.json file**: `npm ERR! Couldn't read dependencies.`<br /><br />**Native module doesn't have a binary distribution for Windows**:<br />`npm ERR! \cmd "/c" "node-gyp rebuild"\ failed with 1` <br />or <br />`npm ERR! [modulename@version] preinstall: \make \|\| gmake\` | |
| 152 | +|`Couldn't resolve host 'hostname'`|The address information for the `azure` remote is incorrect.|Use the `git remote -v` command to list all remotes and their associated URLs. Verify that the URL for the `azure` remote is correct. If necessary, remove the incorrect URL by using `git remote remove` and then recreate the remote with the correct URL.| |
| 153 | +|`No refs in common and none specified; doing nothing. Perhaps you should specify a branch such as 'main'.`|You didn't specify a branch when you ran `git push` or you didn't set the `push.default` value in `.gitconfig`.|Run `git push` again and specify the main branch with `git push azure main`.| |
| 154 | +|`Error - Changes committed to remote repository but deployment to website failed.`|You pushed a local branch that doesn't match the app deployment branch on `azure`.|Verify that the current branch is `master`, or change the deployment branch by following the instructions at [Change the deployment branch](#change-the-deployment-branch). | |
| 155 | +|`src refspec [branchname] does not match any.`|You tried to push to a branch other than `main` on the `azure` remote.|Run `git push` again, and specify the main branch with `git push azure main`.| |
| 156 | +|`RPC failed; result=22, HTTP code = 5xx.`|You might have tried to push a large Git repository over HTTPS.|Change the git configuration on the local computer to set a higher value for `postBuffer`. For example: `git config --global http.postBuffer 524288000`.| |
| 157 | +|`Error - Changes committed to remote repository but your web app not updated.`|You deployed a Node.js app with a *package.json* file that specifies added required modules.|Review the `npm ERR!` error messages that appear before this error for more context. The following causes are known causes of this error and the corresponding `npm ERR!` messages:<br />**Malformed package.json file**: `npm ERR! Couldn't read dependencies.`<br />**Native module doesn't have a binary distribution for Windows**: `npm ERR! \cmd "/c" "node-gyp rebuild"\ failed with 1` or `npm ERR! [modulename@version] preinstall: \make \|\| gmake\` | |
180 | 158 |
|
181 | 159 | ## Related content
|
182 | 160 |
|
|
0 commit comments