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?

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

1 Answer 1


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.

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

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.