How to use an Azure DevOps Repo behind a proxy

So you’ve just created an Azure DevOps repo. Congratulations! I’m sure you’re going to enjoy using the impressive suite of tools that Microsoft has created to make our lives as developers easier.

If you just stumbled upon this post and don’t actually have an Azure account yet, did you know you can try Azure services for free for 12 months? Sign up for a free account here: https://azure.microsoft.com/en-us/free/

Now, let’s connect our local machine to the repo. That shouldn’t be too hard, right? We’ll just select Clone:

Azure DevOps Repo Clone Button

Copy the Command line url:

Azure DevOps Repo Clone HTTPS URL popup

Then go to the command line and run git clone with the copied url. It should look something like this:

git clone https://{orgName}@dev.azure.com/{orgName}/{projectName}/_git/{repoName}

You’ll be prompted to enter your password and that’s it!

Actually, maybe not. At least not for me. You see, I was trying to do this from behind a corporate proxy, so I ran into some issues. And since I definitely wasn’t going to settle for hopping off and back on VPN every time I wanted to push some code to Azure, here’s how I was able to connect to an Azure DevOps Repo behind a proxy.

Create a Personal access token (PAT)

First of all, using my username and password didn’t work for authentication, so I had to create a Personal access token (PAT). To do that, go to User Settings and select Personal access tokens in your Azure project:

Azure DevOps User settings menu, Personal access tokens highlighted

From there, create a New Token, name it whatever you like, and copy it somewhere safe.

Change the git clone url

Next, try to clone the repo again, but now use this completely different secret url:

git clone https://{PAT}@{orgName}.visualstudio.com/{projectName}/_git/{repoName}

So we provide the PAT in the clone url, and instead of using dev.azure.com for the host, we use visualstudio.com. Don’t ask me why, it’s a secret.

Add proxy settings to your .gitconfig

And one more thing. Since this whole problem is caused by the proxy server, make sure your proxy settings are set in your .gitconfig file:

git config --global http.proxy http://{username}:{password}@{proxyServer}:{port}
git config --global https.proxy http://{username}:{password}@{proxyServer}:{port}

Now that should be it. Go forth and confidently connect to an Azure DevOps Repo behind a proxy. Hopefully I could spare you a few Google searches. Happy coding!