Authentication Fail When Trying to Add Package to My Project via HTTPS with Swift Package Manager

Viewed 2552

In my Xcode settings, I'm logged into my GitHub account (where 2fa is turned on) as a Source Control Account. I currently have it set up to use SSH and my SSH key. I've created an access token and securely saved that string on my machine. I can successfully add the package when I use an SSH URL (which makes sense, such as git@github.com:{username}/{repo_name}.git.

I can't get adding via HTTPS to work for some reason. It always results in the following error:

Error while fetching remote repository: https://github.com/{username}/{repo_name}.git

Authentication failed because no credentials were provided.

Is this a known Xcode error? I haven't found an answer here on SO. Is it because I'm using 2FA? All the packages have the same instruction which is essentially "Just copy and paste this URL into SPM to add" but that's never worked for me.

Would love some insight here. Thanks!

2 Answers

We solved this by removing a problematic setting in $HOME/.gitconfig:

Deleting:

[url "git@github.com:"]
    insteadOf = https://github.com/

Honestly not sure why this was happening (sometimes crashing!) in my project, but I noticed it worked fine in other Xcode projects. So, I sunk a couple days into re-creating the project file from scratch (new project, same name, re-add files, re-add packages, re-set settings, etc.).

That fixed it and now I can add and remove packages all I want

Related