PowerShell 1 min read
How to Push an Existing Repository from VS Code to Azure DevOps by PowerShell
Michael Wu ·
I discovered that pushing a local repository to Azure DevOps requires pre-creating the repository first, rather than having the push command create it automatically.
Steps
Step 1: Create Local Folder and File
mkdir TestRepo
New-Item -Type File .\TestRepo\test.ps1
Step 2: Initialize Git Repository
git init
git add .
git commit -m "add a new file"
Step 3: Create Repository in Azure DevOps
Navigate to the Azure DevOps site and create a new repository. This is a critical step — you need to pre-create a repo then push to it.
Step 4: Copy Push Commands
From the new Azure DevOps repository page, locate the section labeled “push an existing repository from command line” and copy the provided commands.
Step 5: Execute in VS Code
Paste and run the copied commands in VS Code to complete the push operation.
Key Takeaway
The main challenge was the misconception that a push operation would create a new repository. Users must manually create the repository in Azure DevOps before pushing local code to it.