How to create an azure repository directly from git bash command line? (without entering the browser)

Update

I am trying to create a repository from git bash command line to AzureDevops team platform,

I've been following these instructions:

https://docs.microsoft.com/en-us/azure/devops/repos/git/share-your-code-in-git-cmdline?view=azure-devops

I am having trouble with the prerequisites, I ran the next lines:

az --version                          # version is greater than v2.0.49
az extension add --name azure-devops  # no problem with this line 
az devops login --organization org_url 
PAT                                   # problem arises here.... 

The next line arises after running end line:

Failed to authenticate using the supplied token.

I am creating the PAT by following these instructions:

https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page

Do I have to ask for manager credentials or else what could I do to solve this issue?


Solution 1:

From the error message, you probably need to install the Azure CLI. You must have at least v2.0.49, which you can verify with az --version command. Then you can run the az login command to login with your Azure account.

Update

Just follow the article. You can do the steps in your git bash or other terminals:

  1. Download and install Azure CLI and add Azure DevOps extension.
   az extension add --name azure-devops
   az login #login in with your Azure account
   az devops configure --defaults organization=https://dev.azure.com/contoso project=contoso
  1. Create a local Git repo for your code. If your code is already in a local Git repo, you can skip this step.
cd /home/fabrikam/fiber
git init .
git add --all
git commit -m "first commit of my code"
  1. Create a new Git repo in Azure Repos and connect your local repo to the Git repo in Azure Repos using remoteUrl in the response from your creating Git repo :
az repos create --name  mywebapprepos
git remote add origin https://xxx.xxx.com/webapp-test/_git/mywebapprepos

enter image description here

  1. Before pushing your code, you need to login in with your Azure account to authenticate. For me, it will prompt the Windows UI to login in with my account.
git push origin master

enter image description here

Solution 2:

when I ran az repos create --name mywebapprepos the terminal returns ClientRequestError: 403 FORBIDDEN Operation returned a 403 status code.

According to this error message, I suggest you can try to log in Azure Devops using Full Access PAT(personal access tokens).

enter image description here

Here is a doc about Creating PAT in Azure Devops.

Then when you execute the az devops login , you could use the Full Access PAT as the Identity authentication method.

You can enter PAT in the next line.

Finally, you could try to run the az repos create --name again.

Update:

You can also try to use the following steps:

1.Create a file to save the PAT.

enter image description here

2.You could run the following command:

cat ado.pat | az devops login --organization https://dev.azure.com/orgname

enter image description here

For more detailed information, you could refer to this doc.