| title | Deploy From a Local Git Repository |
|---|---|
| description | Learn how to configure and carry out local Git deployment to Azure App Service. |
| ms.topic | how-to |
| ms.date | 06/26/2025 |
| ms.reviewer | dariac |
| ms.custom | devx-track-azurecli, devx-track-azurepowershell |
| author | cephalin |
| ms.author | cephalin |
| ms.service | azure-app-service |
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 from a Git repository on your local computer.
Note
Local Git deployment requires Source Control Manager (SCM) basic authentication, which is less secure than other deployment methods. If basic authentication is disabled, you can't configure local Git deployment in the app's Deployment Center.
To complete the steps in this article, you need:
-
An Azure account and subscription with permission to create App Services resources. [!INCLUDE quickstarts-free-trial-note]
-
Git installed, and a local Git repository that contains app code to deploy.
You can clone a sample Node.js app repository by running the following command in your local Bash terminal window:
git clone https://github.com/Azure-Samples/nodejs-docs-hello-world.git
-
If you want to use the Azure CLI commands, the latest version of the Azure CLI installed on your local machine. Sign in to Azure using az login.
-
If you want to run the Azure PowerShell commands, the latest version of Azure PowerShell installed. Sign in to Azure using Connect-AzAccount.
[!INCLUDE Prepare repository]
You need deployment user credentials to authenticate and deploy your app. These are different from your Azure subscription credentials, and you can use either user-scope or application-scope credentials.
A user-scope deployment user for local Git deployment only needs a user name, not a password. You can set the user-scope user name by running the Azure CLI command az webapp deployment user set --user-name <username>, or under User-scope on the Local Git/FTPS credentials tab of an app's Deployment Center.
Once you create your user-scope deployment user, you can use it for all the App Service apps you have access to. For more information, see Configure user-scope credentials.
An application-scope deployment user is app-specific and is created automatically when you create an app. You can get the application-scope user credentials to use for deployment from the Local Git/FTPS credentials tab in the app's Deployment Center.
You can create and configure a Git-enabled app, or configure local Git deployment for a preexisting app, by using Azure CLI, Azure PowerShell, or the Azure portal.
-
To create a new web app configured for local Git deployment, run az webapp create with the
--deployment-local-gitoption. For example:az webapp create --resource-group myResourceGroup --plan myAppServicePlan --name myApp --runtime "NODE:24-lts" --deployment-local-git -
To configure local Git deployment for an already-existing app, run az webapp deployment source config-local-git. For example:
az webapp deployment source config-local-git --name myApp --resource-group myResourceGroup
Either command produces output that includes a URL, such as:
Local git is configured with url of 'https://[email protected]/myApp.git'
The preceding URL contains the user-scope deployment user name contoso-user. If you don't have a user-scope deployment user name, the URL uses the application-scope user name, for example https://[email protected]/myApp.git.
Use this Git clone URL to deploy your app in the next step.
-
In a local PowerShell terminal, change directory to the root of your cloned Git repository.
-
To create a new web app, run New-AzWebApp. For example:
New-AzWebApp -Name myAppWhen you run this cmdlet from a directory that's a Git repository, it automatically creates a Git remote repository named
azurefor your App Service app. -
For your new or preexisting app, run the Set-AzResource cmdlet to set the
scmTypetoLocalGit. For example:$PropertiesObject = @{ scmType = "LocalGit"; } Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName myapp ` -ResourceType Microsoft.Web/sites/config -ResourceName myApp/web ` -ApiVersion 2015-08-01 -Force
In the Azure portal, 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. For the sample repository, use the Node.js instructions and select Node 24 LTS for Runtime stack on the Basics tab.
At the bottom of the Deployment tab on the Create Web App page, set Basic Authentication to Enabled.
When the app is created, select Go to resource.
-
On the Azure portal page for your new or preexisting app, select Deployment Center under Deployment in the left navigation menu.
-
On the Settings tab, select Local Git from the dropdown list next to Source, and then select Save.
:::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.":::
-
When the configuration completes, 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.
To deploy the app to Azure, create a remote branch if necessary, make sure you're deploying to the correct branch, and then push your code to the remote.
If you used Azure PowerShell New-AzWebApp to create the app from the sample code, the azure remote was already created. Otherwise, follow these instructions to create the remote:
-
In a local terminal, change directory to the root of your cloned Git repository.
-
Add a Git remote named
azureby using your Git clone URL. If you don't know your Git clone URL, usehttps://<app-name>.scm.azurewebsites.net/<app-name>.git.git remote add azure <git-clone-url>
App Service repositories deploy files to the master branch by default. If your preexisting local files are in the master branch of your repository, you can now deploy your app by running git push azure master.
However, many Git repositories, including the sample code repository for this article, use main or another default branch name. To deploy to the correct branch, you must either explicitly deploy to the remote master branch, or change the deployment branch to main or other branch name and deploy to that branch.
Explicitly deploy to master from your main branch by using the following push command:
git push azure main:masterOr change your app's DEPLOYMENT_BRANCH app setting to main and then push directly to main, as follows:
-
Azure CLI:
az webapp config appsettings set --name <app-name> --resource-group <group-name> --settings DEPLOYMENT_BRANCH='main' git push azure main -
Azure portal:
- On the portal page for your app, select Environment variables under Settings in the left navigation menu.
- Select Add, add an application setting with the name DEPLOYMENT_BRANCH and value main, and select Apply.
- In the terminal window, run
git push azure main.
If the Git Credential Manager dialog appears after you push your code, enter your user-scope deployment user name or application-scope user name and password. If your Git remote URL already contains the sign-in information, you aren't prompted to enter it.
Review the output from the push command. You might see runtime-specific automation, such as npm install for Node.js, MSBuild for ASP.NET, or pip install for Python. If you get errors, see Troubleshoot deployment.
Go to the Azure portal and 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!.
The following common errors might occur when you use local Git to publish to an App Service app in Azure:
| Message | Cause | Resolution |
|---|---|---|
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. |
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. |
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 correct branch with git push azure <branch>. |
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 Push to the correct branch. |
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. |
RPC failed; result=22, HTTP code = 5xx. |
You 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. |
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 known causes of this error produce the corresponding npm ERR! messages:Malformed package.json file: npm ERR! Couldn't read dependencies.Native module doesn't have a binary distribution for Windows: npm ERR! \cmd "/c" "node-gyp rebuild"\ failed with 1or npm ERR! [modulename@version] preinstall: \make || gmake\ |