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?

2
  • Inside the .git directory is a config file which specifies the upstream. You can edit this to change from https to ssh.
    – icarus
    Commented Oct 30, 2016 at 4:28
  • I'll give that a try. Commented Oct 30, 2016 at 5:24

2 Answers 2

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.

2
  • Indeed, this is purely a Git issue. I've solved it using a Git credential store. Commented Dec 14, 2016 at 1: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
    Commented Sep 27, 2021 at 16:04
0

I had the same problem and as suggested by @tarsius second link, git credential manager solved it. There is a nice walk through of the steps, related to R, on this blogpost

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.