git clone: Authentication failed for <URL>

Trying to access private corporate tfs. They gave me access by giving appropriate rights to windows user (domain\login).

I'm fine with accessing web interface of tfs, browse repository and stuff.

But when I try to run

 git clone https://tfs.somehostname.com/tfs/somefolder/_git/therepository

It fails with

Cloning into 'therepository'...

fatal: Authentication failed for 'https://tfs.somehostname.com/tfs/somefolder/_git/therepository/'

Tried with home pc without corporate network stuff - same error.

Tried in PowerShell, Git Bash, Clone via VisualStudio - same error.

SSH is closed (gave request timeout).

Web & Git both ask for credentials once (tried deleting in Credentials Manager - asks again, after submitting web is fine, git fails)

Corporate helper tried to help, but all he gave is tfs logs. He says, my username doesn't come with requests (tracked by syncing my attempts timestamps with logs).

2018-07-19 07:04:00 SOMEIP GET /tfs/SOMEFOLDER/_git/REPOSITORY/info/refs service=git-upload-pack 443 - ANOTHERIP git/2.12.2+(Microsoft+Windows+NT+6.3.9600.0;+Win32NT+x64)+CLR/4.0.30319+VS15/15.0.0 - 401 2 5 62
2018-07-19 07:23:00 SOMEIP GET /tfs/SOMEFOLDER/_git/REPOSITORY/info/refs service=git-upload-pack 443 - ANOTHERIP git/2.18.0.windows.1 - 401 2 5 62
2018-07-19 07:23:00 SOMEIP GET /tfs/SOMEFOLDER/_git/REPOSITORY/info/refs service=git-upload-pack 443 - ANOTHERIP git/2.18.0.windows.1 - 401 1 3221225581 187

while others include it

2018-07-19 05:44:27 SOMEIP GET /tfs/SOMEFOLDER/_git/REPOSITORY/info/refs service=git-upload-pack 443 DOMAIN\LOGIN ANOTHERIP git/2.12.2+(Microsoft+Windows+NT+6.1.7601+Service+Pack+1;+Win32NT+x64)+CLR/4.0.30319+VS15/15.0.0 - 200 0 0 265

I faced same error on my PC. I was trying to clone a repository. My PC was absolutely new with a freshly installed operating system. I was using Git bash as my Git client. When I ran Git's command to clone a repository it was not prompting me for user id and password which will be used for authentication. It was a new PC so no credentials were cached by Windows credential manager.

As a last resort, I manually added my credentials in credentials manager.

Go to > Control Panel > Click User Accounts > Click Credential Manager > Click Windows Credentials

Now, click Add a Windows credential in Windows Credentials section as shown below:

enter image description here

Now, enter the details as shown in the form below and click OK:

enter image description here

I had put the details as below:

Internet or network address: <gitRepoServerNameOrIPAddress>
User Name: <DomainName\MyUserName>
Password: <MyPassword>

Next time when you run any Git command targeting a repository set up on above address, this manually cached credential will be used.

Note:

  1. If you have Git bash command line already open then close and reopen it for the credential changes to take effect.
  2. Also remember that when your domain account password changes next time then you'll have to update the newly set password on this screen as well.

Go to > Control Panel\User Accounts\Credential Manager > Manage Windows Credentials and remove all generic credentials involving Git. (This way you're resetting all the credentials)

After this, when you clone, you'll be newly and securely asked your Git username and password instead of Authentication error.

Hope it helps.


Adding username and password has worked for me: For e.g.

https://myUserName:myPassWord@myGitRepositoryAddress/myAuthentificationName/myRepository.git

For cloning a private repository simply putting the password and username will not be enough as the terminal will not tell but you will have to copy the personal_access_token using the github account and put it in the place of your password.

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

Further you can easily access your token through the steps given below: - Go to Settings
Developer Setting
Personal_acess_token
Now check the repo column and now click on Generate token Generate token
Congratulations!!
Now copy and it and paste it when the terminal asks for password.

NOTE: - Treat your tokens like passwords and keep them secret