8

What is the best way to use Magit with GitHub personal access tokens?

Right now, pushing to GitHub causes Magit to prompt me for a username and password. I have to provide the access token instead of my regular password to authenticate.

Apparently, cloning with SSH instead of HTTPS is the way to go. However, I've already cloned a large number of repos w/ HTTPS. Can I get them to use the token I've specified in my .gitconfig file?

Tianxiang Xiong
  • 3,848
  • 16
  • 27

1 Answers1

3

Magit doesn't deal with authentication directly and leaves that all to Git. The only thing Magit does is that when Git asks the user to provide a password or passphrase, then it forwards that question to the user and later hands the reply to Git.

Git provides many alternative methods for remembering the secret needed to access a remote repository and they all work with Magit. Some of the available options are described here, here, and here.

If you can access remote repositories on the command line without having to provide a secret, but not inside Magit, then that is a configuration issue. For example on Windows your shell and Emacs may not agree on the location of $HOME. See Pushing with Magit from Windows.

tarsius
  • 25,298
  • 4
  • 69
  • 109
  • Indeed, this is purely a Git issue. I've solved it using a [Git credential store](https://git-scm.com/docs/git-credential-store). – Tianxiang Xiong Dec 14 '16 at 01:59
  • fwiw, I solved this problem (except now that PATs are required, I get authentication failures, so it's a slightly different problem) by deleting the remote through magit, and re-adding it (through magit). After that, sure enough, the git Credential Manager came up and did its magic. – JohnL4 Sep 27 '21 at 16:04