SPM, Github, internal dependencies & SSH auth
Ever tried using Swift Package Manager with dependencies hosted on Github while using SSH? And resolving subdependencies when adding a SPM package through Xcode? Still having nightmare about it? Dry your tears and cry no more: you've come to the right place.
Some companies and open source libraries reference Swift Package Manager dependencies using the https://
endpoint, such as https://github.com/org/repo.git
. Some companies even use the https
URLs for their own internal dependencies.
This can lead to the following issue when you are used to authenticate with Github using an SSH key
Fetching from https://github.com/org/repo.git
skipping cache due to an error: Failed to clone repository https://github.com/org/repo.git:
Cloning into bare repository '/Users/user/Library/Caches/org.swift.swiftpm/repositories/repo-d43c1afe'...
remote: Repository not found.
fatal: repository 'https://github.com/org/repo.git/' not found
Or this issue, when adding SPM dependencies using Xcode

Which won't go away despite selecting a valid account from the drop down and inputting, again and again, a valid github personal access token. Why? Because somehow Xcode can't deal with the mixing up of both https
URLs and ssh keys.
Which is tiring.
How do we solve that?