I haven’t written a ‘things I learnt’ post for a while, mainly because I’ve been wrapping those into my main posts. However, after going round in circles for ages with this problem, I wanted to share the solution quickly in case it helps anybody else!
I’ve recently started using RStudio Cloud as a platform to share training resources. Unfortunately, I stumbled at almost the first hurdle when I tried to clone my relevant GitHub repo. I normally use my SSH key for cloning, but here I needed to paste in the repo URL, which I guess is similar to HTTPS authentication. This led to a prompt to provide my username and password.
I dutifully filled in my GitHub username and password, only to see the git clone fail.
Every time I tried, I was presented with the messages “invalid username or password” and “authentication failed”. I knew I was getting my password right after carefully checking and trying multiple times but that wasn’t getting my anywhere.
I spent a frankly embarrassing time trying to find an answer. Most solutions I found were based on the repo having been authenticated at one point or another and reconnecting it, rather than not being in the repo at all. I also managed to clone some other repos, which were public, so realised it might have something to do with the privacy settings - although this wasn’t that encouraging as I couldn’t change those.
Eventually, somebody mentioned two factor authentication and a lightbulb went off. I have 2FA enabled but there was no point in the process to provide the second authentication! But what was the fix?
Using the help available on GitHUb, I found out that using HTTPS authentication meant you would need a personal access token. Details of how to create one are available here but the key thing is that when you are asked for your password, you need to provide the PAT, not your normal GitHub password!
Although the GitHUb help pages are very useful for this, it is not clear at all that this is what is required when you first see the pop ups…so hopefully this post reaches people like me who are frantically googling the error messages looking for a way to clone their project.