Change git repo to use SSH not HTTPS

Software

I cloned a repo from GitLab this morning, made some changes, and was about to commit when I got this:

remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'read_repository'
	or 'write_repository' scope for Git over HTTP.
remote: You can generate one at
	https://gitlab.com/-/profile/personal_access_tokens

Sure enough, listing the remote sources showed HTTPS not SSH:

$ git remote -v
==> origin https://gitlab.com/rubenerd/repo_name (fetch)
==> origin https://gitlab.com/rubenerd/repo_name (push)

So I changed:

$ git remote set-url origin git@gitlab.com:rubenerd/repo_name.git

Donezo.

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person in bios. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.