44

I cannot clone a simple repository from Azure DevOps. OS: Ubuntu 18.10

I do this:

  • Got to Azure DevOps
  • Click on the top right corner on my user name
  • Go to the security tab
  • Create a PAT with all the scope (to be sure there is no scope problem)
  • Copy the PAT to the clipboard
  • Paste the PAT somewhere else to confirm the PAT has been copied correctly (I know... not safe but that is out of the scope of this question)
  • Go to my console
  • Issue: git clone https://myorganization.visualstudio.com/myproject/_git/myrepo/
  • I enter the user name and the password (the PAT)

I keep getting this message from Git: fatal: Authentication failed for 'https://myorganization.visualstudio.com/myproject/_git/myrepo/'

I was reading the solutions of other people but none worked for me. I also tried this:

  • Pass the token in the form https://usename:[email protected]/myproject/_git/myrepo/ I am really surprised people say this worked... for my git complains because believes the : means the port.
  • Tried to activate/deactivate credential manager of git * Tried on Windows and Ubuntu.
  • Tried to activate and deactivate the simple credentials.
  • Tried with the simple credentials, i.e. username + password.
  • Tried to put my user name in https://username@....
  • Tried to use SSH
  • Tried to use the http.extraHeader in the git command with the header being
    Authorization: Basic Base64Encoded(uname:PAT)
  • Tried to use the http.extraHeader in the git command with the header being
    Authorization: Bearer PAT
  • Tried to use the VSCode client. It generates the PAT by itself but still cannot authenticate and clone.
  • Tried to use the Rider VSTS client. It generates the PAT by itself but still cannot authenticate and clone.
  • Tried to use the git credentials manager for Linux. It promps the Code and when we authenticate in the browser, it generates a PAT successfully. Still, after that cannot authenticate.

Any clue why this is not working?

4
  • Did you try to use SSH key authentication? Commented Nov 1, 2018 at 19:41
  • 1
    Can you clone using username (email) and password (not PAT)? Commented Nov 1, 2018 at 19:45
  • 1
    No. I want to use HTTPS. As the question states, yes I tried usename and password but same result.
    – JJ F
    Commented Nov 2, 2018 at 1:44
  • This is setting the port. https://usename:[email protected]:443/myproject/_git/myrepo/
    – Dennis
    Commented Aug 11, 2022 at 13:39

9 Answers 9

46

I have had success using PAT like this;

  1. Copy clone URL for your repository e.g.
    git clone https://<domain>.visualstudio.com/<domain>/_git/<repository>
  2. After you have copied your PAT use as:
    git clone https://<PAT>@<domain>.visualstudio.com/<domain>/_git/<repository>

No Username nor password should be required as the PAT should suffice.

5
  • 1
    This works, however I had to add / substitute <project> and <repo> - e.g. git clone https://<PAT>@mydomain.visualstudio.com/myproject/_git/myrepo
    – John B
    Commented Jan 28, 2020 at 22:14
  • Yep it works on Mac OS Big Sur as well. Running the command on terminal in the VS Code.
    – felixwcf
    Commented Jan 4, 2021 at 7:34
  • 1
    This works with new dev.azure.com addresses too. In fact the only style I could get to work. My particular case: https://$(System.AccessToken)@dev.azure.com/<organization>/<project>/_git/<repo> Commented Jun 16, 2021 at 12:23
  • 1
    This worked on my case, thanks for sharing. Commented Mar 28, 2023 at 8:40
  • 1
    I use Azure Devops 2019 on promise but your suggestion does not work. when I've executed git clone https://<PAT>@<domain>.visualstudio.com/<domain>/_git/<repository> command need password.
    – GreenMan
    Commented Sep 10, 2023 at 8:04
29

I've experienced the same issue, and spent quite a while searching for a solution. I finally came across this post which contained a solution in the comments section by Martinius79.

In short, it was required to pass the username and PAT, encoded as base64, through git http.extraheaders in order for it to authenticate.

100% Credit to the original author, just including it here to assist others in locating it:

Example: git -c http.extraheader="AUTHORIZATION: Basic TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh" clone https://tfs.address/tfs/Collection/Project/_git/RepoName

Used basic token BASE64 encoded: TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh

Basic Token BASE64 decoded: MyGitSyncUser:6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

Token is constructed from : In this example: Fictional user name: MyGitSyncUser Used PAT: 6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

I hope this helps!

5
  • This is definitely the correct answer. I struggled with this for a while on Ubuntu, after having successfully testing it on Windows using the plain PAT (without needing to Base64 encode). Note that you need to have a username in base64 encode as per the example. Tried without and it does not work.
    – wanton
    Commented Nov 9, 2018 at 4:11
  • 2
    For me this is not working. I.e. I get the same result as without setting the -c http.extraheader
    – JJ F
    Commented Nov 14, 2018 at 17:09
  • 4
    I added this to my .bashrc: AZURE_PAT="<your PAT>"; AZURE_AUTH_HEADER=$(echo -n "anything:$AZURE_PATH" |base64 -w0); alias azure-git='git -c http.extraheader="AUTHORIZATION: Basic ${AZURE_AUTH_HEADER}"'
    – joemat
    Commented Aug 9, 2019 at 6:21
  • After trying many answers on SO. this fixed my issue. Thanks a lot!
    – Uday
    Commented Mar 2, 2020 at 16:32
  • I too struggled for hours trying all the other suggestions but adding an encoded copy of Azure DevOps username + ":" + PAT into the git clone command worked perfectly...thanks! Commented Jul 17, 2023 at 10:24
12

This official guide procedure worked for me, but with one important point. When base64-encoding, one must put attention to non-printable characters.

The guide says:

MY_PAT=yourPAT      # replace "yourPAT" with your actual PAT
B64_PAT=$(printf ":$MY_PAT" | base64)
git -c http.extraHeader="Authorization: Basic ${B64_PAT}" clone 
https://dev.azure.com/yourOrgName/yourProjectName/_git/yourRepoName

Using "echo" instead of "printf" would insert a newline char, changing the base64 string (probably would work also with "echo -n" but I haven't tried). Also, do not include the username, as per the snippet above.

Used git 2.17.1 on Ubuntu 18.04.

1
  • Well this just ended 2 days of frantic debugging. Thank you!
    – helmesjo
    Commented Mar 23, 2021 at 11:24
4

I was having the same problem and got it solved using HTTPS only.

I figured out that I had to use the terminal only rather than using any "GUI shortcuts" dev.azure provides since they are meant for a git-credential-manager which works fine on windows but is broken for Ubuntu.

Apparently, the dev.azure git repository has a different credentials (which you need to set up) rather than your Microsoft account credential.

Let's say my Microsoft account username is [email protected], with its password Jd1986

This credential will NOT work if you try for git cloning, as you need to generate git credential for your project and then use it.

You can generate git credential from here, enter image description here

After this, Save it and use the set credential. enter image description here

Go to your terminal, and use the HTTP url for git clone and enter the given credential. This worked for me.

4
  • This is the correct answer for Azure DevOps -> Azure DevOps repo imports. I had been getting the errors: Clone URL is incorrect. Clone URL requires authorization.
    – rickjr82
    Commented Jan 15, 2020 at 16:49
  • 1
    you don't need to do this. All you need is this for cloning. accessToken is System.AccessToken $"git -c http.extraheader=\"AUTHORIZATION: bearer {accessToken}\" clone --depth 1 {repo1.ProjectTargetUrl}".BashOut(); And BashOut is just a helper method to convert to a bash command with escape chars Commented Aug 11, 2021 at 16:41
  • And if you need creds generate and ssh cred and apply it to the mac. I believe that is alternate credentials which is very unsafe. You should not use them and Microsoft explicitly says not too. Commented Aug 11, 2021 at 16:46
  • I use Azure DevOps 2019 and it does not have generate git credential
    – GreenMan
    Commented Sep 10, 2023 at 8:14
2

Git http.extraheader & bearer

YAML style Pipelines can use the preset variable System.AccessToken. After examining the formal 'Checkout ...' step at the beginning of the Pipeline I found this step to work in my script:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone --depth 1 https://[email protected]/my-org/my-proj/_git/my-repo'

Note that Azure DevOps job authorization scope may affect this

2
  • You can issue the same command without needing yaml. This is the correct answer Commented Aug 11, 2021 at 16:47
  • One caveat, is the access token cannot push because the pipelines are read only. Commented Aug 11, 2021 at 16:48
1

This is a known regression in curl 7.61.0, which ships with Ubuntu 18.10. The regression was fixed in curl 7.61.1, but Ubuntu 18.10 doesn't have this fix yet. See (and upvote) https://bugs.launchpad.net/ubuntu/+source/curl/+bug/1805203

0
  1. Login into Azure Dev Ops portal.
  2. Go to Project you wish to clone.
  3. Select Repo from left menu.
  4. Click on Clone from right top corner.
  5. Click Generate Git Credential
  6. Enter given https clone url, username & password where you are cloning repository.
  7. you are done!
-3

Ensure you are a member of the Contributor group and that your permissions are not limited for your user or group on the azure repo.

Azure Contributor group has per default permission to clone, fetch, and explore the contents of a repository; also, can create, comment on, vote, and contribute to pull requests.

Any of this permissions can be edited by members of the Project Administrator Group or those having Manage permissions set to Allow for Git repositories as described here.

If your group or user does not have the permission to clone the repository, you will get the behaviour described by the question.

2
  • 2
    Please explain how/why this fixes the described problem.
    – Yunnosch
    Commented Jul 21, 2020 at 12:41
  • Does not answer anything Commented Aug 11, 2021 at 16:48
-4

Try : First delete the git credentials from Credential manager. Try Generating a new personal access token to resolve this error

Error

Go to security ->Personal access token->Add Give Description, select All scopes, click Create Token.

PAT

Copy the token and store it for later use. This token can now be used in place of password for the git user.

Token

1
  • 5
    The error you mention in this post is totally unrelated to my problem.
    – JJ F
    Commented Nov 2, 2018 at 15:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.