123

I am unable to run any commands against my remote repository at Visual Studio Team Services (VSTS) because authentication fails.

I am able to do pulls, etc. through Visual Studio. But only through Visual Studio. Not through Git Bash, or any other tool like SourceTree.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
onefootswill
  • 3,707
  • 6
  • 47
  • 101

7 Answers7

206

You need to enable Alternate Authentication Credentials if you want to use other Git clients outside of Visual Studio...

To set up alternate creds in Visual Studio Team Services (VSTS), click on your name/icon on the top right -> Security -> Alternate Authentication Credentials

Edit: Add more details about this from VSTS (taken from the alternate credentials screen)...

ALTERNATE AUTHENTICATION CREDENTIALS

Some applications that work outside the browser (including Team Explorer Everywhere command line client and the git-tf utility) require basic authentication credentials. Other applications do not properly handle using an e-mail address for the user name during authentication.

To work with these applications, you need to enable alternate credentials, set a password, and optionally set a secondary user name not in the form of an e-mail address. Please note that alternate credentials cannot be used to sign in to the service from a web browser or outside of these applications.

Sean Martz
  • 33
  • 6
Anthony Chu
  • 37,170
  • 10
  • 81
  • 71
  • 1
    @AnthonyChu onefootswill- How to connect to Visual Studio online Git repository without using Visual Studio. Can I use tools like Git Bash, Git-TF. Any help is greatly appreciated – Suhumar Aug 14 '14 at 17:00
  • Thanks for this! Any one know how to store the credentials so I don't have to enter them over and over? – Erick Brown Dec 03 '14 at 03:50
  • 2
    If you're on Windows, give this a try... https://gitcredentialstore.codeplex.com/ – Anthony Chu Dec 03 '14 at 08:07
  • Here's MSFT's documentation on it: https://www.visualstudio.com/get-started/code/share-your-code-in-git-xcode#pat – Oren Apr 17 '16 at 18:12
  • They are no longer recommending Alternate Authentication Credentials in favor of Personal Access Tokens which are time limited and revokeable and can be given individual descriptions. – dragon788 Sep 06 '16 at 15:38
43
  1. Enable alternate authentication credentials and set secondary username

    Enter image description here

  2. Create a personal access token for your Visual Studio Team Services account and copy the token

    Enter image description here

  3. Open Git Bash and go to the folder that you cloned your repository to and enter the following command to make sure it stores the credentials and you don't need to enter it every time:

    git config credential.helper store
    
  4. git pull origin [your branch]

    It asks for user name and password. Enter user name and token as password

    enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Azadeh Khojandi
  • 3,806
  • 1
  • 30
  • 32
  • Yea that worked. I had an existing project I wanted to add to VSTS version control. Got the authentication issue when trying to push the new repo. After doing this (entering username/password), the push worked. – Patrick Borkowicz Sep 11 '17 at 15:44
10

On Windows, you can easily create a Personal Access Token using the Git Credential Manager. It's what Visual Studio Team Services now seems to recommend over the Alternate authentication credentials.

Just install that utility, and then the next time you git pull from Git Bash, it will prompt you for your Visual Studio Team Services access credentials. It will then create a Personal Access Token in your VSTS account, and add a couple of entries to your local Windows Credentials store.

Quote from the site:

It magically works when credentials are needed. For example, when pushing to Visual Studio Team Services, it automatically opens a window and initializes an oauth2 flow to get your token.

Lyall
  • 895
  • 9
  • 20
4

I noticed the wording (and location) of the menus changed in Visual Studio Team Services. It is now located in the drop-down menu at the top-right corner (with your initials or photo) Security → Alternate authentication credentials. Just enable and make up your username and password.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
megamaiku
  • 434
  • 4
  • 11
2

When using Atlassian SourceTree you need the basic credentials setup in Visual Studio Team Services (VSTS) like in the accepted answer.

Then in SourceTree go to menu ToolsOptionsAuthentication tab.

You need to set the non-email username that you set up as basic username credentials for the XXX.visualstudio.com host.

You will then be prompted for the password when accessing that VSTS Git repository.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hawkeyecoder
  • 571
  • 4
  • 10
2

Downloading the latest version of Git and including the Git Credential Manager worked for me.

Use Git Credential Managers to Authenticate to VSTS

Kols
  • 3,641
  • 2
  • 34
  • 42
Nhan
  • 1,405
  • 1
  • 13
  • 16
1

As per 2017-06-21, the page to enable alternate authentication settings is at the link https://*YOUR_USER_NAME*.visualstudio.com/_details/security/altcreds.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Risky Pathak
  • 598
  • 5
  • 16