VS2022 Authentication fails when pushing code to github - github

I am having the below error when pushing code to github
remote: No anonymous write access.fatal: Authentication failed for 'https://github.com/username/repo.git/'
Tried resolving by doing the following by doesnt resolve the issue
setting origin to https://personalAccessCode#github.com/username/repo.git
--> prompt to login using browser login, code, token
--> tried all and all didnt work
setting origin to https://username:personalAccessCode#github.com/username/repo.git
--> prompt above error when push
Anyone have encounter this on VS 2022 community edition?

Thank all for your help. I managed to successfully push code to git after removing a global settings that set the PAT access token which I use it to connect Azure DevOps
git config --global http.extraHeader

First, the URL should not include your token (you can include your GitHub user account name).
Second, VS2022 has an integration with a Git credential helper: check if your is set to GCM (or GCM Core, even though GCM Core has been replaced by GCM).
Both GCM or GCM core are packages with the latest Git for Windows, so make sure to use the latest one.
Below is the result I have got after changing URL and credential-helper as suggested. But still having the same error

Related

Re-authorize the OAuth Application in GitHub CLI

I'm part of an organization, so I'm trying to clone a repo that is inside of that organization but every time that I've tried I get this error:
Cloning into 'diretory'...
remote: The `X' organization has enabled or enforced SAML SSO. To access
remote: this repository, you must re-authorize the OAuth Application `GitHub CLI`.
fatal: unable to access 'https://github.com/X/Y.git/': The requested URL returned error: 403
Have you ever had a similar problem?
What fixed it for me was to open the Credentials Manager of Windows and delete all GitHub-related entries. Then on my next interaction with GitHub, from Visual Studio in my case (should be similar for GitHub CLI), I got a prompt to sign in and after that, it all worked fine.

How to connect my GitHub Enterprise Account with Visual Studio Code

I want to know if it's possible to connect my github enterprise account of my organization to vs code, and if so how?
I know how to sign in with a normal github account on vs code but it doesn't work for github enterprise. I already looked up online but couldn't find any answers.
In the vs code settings there is an option called github enterprise: Uri. I put there the url of my github organization "github.organizationname.com" but I don't know what else I need to do.
Here's what worked for me on vs code 1.62.3.
Clone the GitHub Enterprise repo outside of vs code (ie, using git cli in a terminal or GitHub Desktop).
In vs code, open the folder containing the cloned repo.
And just like magic, it works. If you click on the source control tab in vs code, you can pull changes and make commits. Actually, it might not work quite yet if your cloned project doesn't have your personal access token saved. If you need to do that, you can find instructions in this answer to a different question
I have set it up in the vscode settings like so:
Then it asked for my personal access token. This is token can be created under "settings" -> "developer options"
see: https://docs.github.com/en/enterprise-server#3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
It is possible to login using GitHub enterprise from VS Code without using personal access token or SSH keys. User can login by SSO if session already exist in browser else will need to sign in using their credentials. One of the ways to achieve this is to install Git Credential Manager. Git Credential Manager (GCM) is a secure Git credential helper built on .NET that runs on Windows, macOS, and Linux.
Compared to Git's built-in credential helpers (Windows: wincred, macOS: osxkeychain, Linux: gnome-keyring/libsecret) which provides single-factor authentication support working on any HTTP-enabled Git repository, GCM provides multi-factor authentication support for Azure DevOps, Azure DevOps Server (formerly Team Foundation Server), GitHub, Bitbucket, and GitLab.
For installing GCM based on OS follow the given link:
https://github.com/GitCredentialManager/git-credential-manager
Once GCM is installed and you try to clone a repository you will be able to see Enterprise login page. This can be achieved by using other Git Oauth Authorized Apps such as GitHub CLI.
Another option is to access with you microsoft email and then , the Github enterprise signing option will be added in "Account" just click it and you now will have access to GithubEnterprise
Account bottom in green
more reference here is the link:
https://learn.microsoft.com/en-us/visualstudio/ide/work-with-github-accounts?view=vs-2022

Deprecated password authentication with github warning

Hello community can you please help me out, not very knowledgeable in this area
I got an email from git saying that personal password is no longer gonna be supported and that team city was using it so I went into GitHub and generated a token and added to the VCS in the, after our next deploy I got an email from GitHub saying, you are still using the password dummy, so I asked our server guy to update TeamCity as we were several versions behind, so he did and we ran a deploy again today. I pay a visit to the VCS again and saw my Authentication method was set to Password/Token. I got no email from GIT this time saying I was dummy and "Developer Settings/Personal access tokens" mention TeamCity has used it but TeamCity keeps saying this ▼▼▼▼ any ideas ?? Thanks.
git) https://github.com//xxxxxxxxxx is using deprecated password authentication with github.com and will soon stop working
Please consider switching to either personal access token or to SSH private key authentication.
Edit VCS root
Solution as mentioned in the error.
It is also mentioned on TeamCity documentation
You may either use SSH priv/pub keys as authentication or "Personal Access Token".
I can tell by git) https://github.com//xxxxxxxxxx that you are currently using HTTPS instead of SSH to source your VCS, so the most similar solution is GitHub Private Access Token (linked: how-to)
Go to Setting > Developer Settings > Personal Access Token and click "Generate New".
If this is a private GitHub repo, you will need to tick the "repo" scope.
On your TeamCity VCS change the password to be the Personal Access Token you generated.
Tip: since you can not view the PAT after generating nor after using on the VCS, it is recommend to set the PAT as a root configuration variable, so you can call it on this VCS, build features, or other future use.

How do I know which git authentication method is being used?

Is there a way to verify through which way I'm authenticating to Azure DevOps?
Am I authenticating through my SSH key?
Am I authenticating through Azure CLI?
Am I authenticating through Azure Account extension in VSCode?
I found setting GIT_TRACE=1 to be useful for debugging Git. (I found that from this page.)
git config --list --show-origin will also show if you're configured to use any credential.helper such as Git Credential Manager Core.
For git authentication with Azure DevOps, the first thing I'd do is to run
git remote show origin
If the Fetch and Push URLs start with git:, you're using an SSH key. If it starts with https:, it's going to do an OAuth browser login to Azure DevOps, and then display a message telling you that you're signed in and can close the browser window, at which point Git will have the credential it needs to work with the remote repository. In my experience, it works the same way in VS Code - it uses whatever credential the Git application has negotiated.
The Azure CLI should not come into play with Git - it can be used to manipulate Azure DevOps features, but does not participate directly in the source control process (other than allowing things like PR submission, etc.)

Azure Devops clone This is not a valid source path in source tree

I have managed to finally add my devops account in sourcetree using the https://orgname.visualstudio.com path
Now I am having issues cloning the repository
I am using the path that devops gives me
https://orgname#dev.azure.com/orgname/MyProject/_git/MyRepo
but I get an error saying
This is not a valid source
The details reveal authentication issues... Yet it authenticated fine when adding the account.
What is going on? Does the azure account have to be the default account?
I managed to fix this by changing from the sourcetree embedded git to my system git Tools>Options>Git>Git Version>Select System. Afterwards when trying again it prompted me to login on my organization domain with 2 factor as if logging in on the devops web app directly.
My system Git is using manager-core for the credential management which is probably not the same system which the embedded version used.
I tried the above solutions (and more) but for me what in the end solved the problem was that the git-password I first wrongly entered when I tried to access the repo had been saved in Keychain (MacOS) and when I tried again this password was used without giving me the option to type it in again. I deleted the password to the Azure DevOps project in Keychain and then got prompted to enter the password again whereafter I pasted the Personal Access Token (!!) generated in Azure Devops and it finally worked!
It could happen when you entered wrong credentials and you don't get asked again, try this:
Go to : Sourtree->Preferences->Advance (tab)
Under: "Default usernames for URLs which do not include one:" delete your wrong credentials.
Try accessing your repo again with right credentials.
This is not the issue which caused by Azure devops. No matter https://xxx.visualstudio.com, or the URL which like dev.azure.com, they should all available git source.
For me, I just try with multi different git URLs, and found the few of URLs are failed with same error with you. But it prompt This is a git repository after I exit the SourceTree and re-configure the clone with same URL which encountered the error previously.
This seems be the most common Sourcetree problem which encountered by many users, not just the URL of azure devops that you occurred.
Check this thread, and try with its recommend way:
Open source tree, Tools -> Options -> Click on Git Tab -> Update
Embedded Git.
Or, consider the method I used: exit the Sourcetree, and re-configure the clone with same URL. (Not recommend since this can not permanently solve this issue)