4

Instead of memorizing all of my passwords, I use a password manager to store them for me. Currently, since I use Magit for most Git purposes, I need to go through several steps in order to push:

  1. P P RET
  2. C-g
  3. M-x term RET RET
  4. git push RET
  5. Copy my password from my password manager
  6. C-c C-j C-y RET

And then afterward, I seem to have a still-running process from Magit's failed push, in addition to the Term mode buffer I created, to deal with.

Is there a less laborious way to enter my password when pushing with Magit?

Edit: ... oh. Well, this is embarrassing. You can apparently just hit C-y directly when Magit asks for your password. I thought I tried that before, but apparently not.

However, it seems that passwords entered this way are not stored in Git's credential cache, so I now need to enter my password every time I push. Is this a bug?

  • 1
    You can usually avoid passwords by using SSH access. – abo-abo Oct 4 '15 at 18:24
  • @abo-abo Do you mean that I would never need to enter a password except when cloning, or that I would only need to enter a password once a day or so? Because if you mean the latter, I already have my cache set to 24 hours timeout. – Sam Estep Oct 4 '15 at 22:34
  • 1
    "it seems that passwords entered this way are not stored in Git's credential cache[...] Is this a bug?" - Yes, it seems so. github.com/magit/magit/issues/2309 – npostavs Oct 5 '15 at 3:39
  • I mean by giving my public SSH key to the remotes I never enter a password. Ever. And it's very safe. – abo-abo Oct 5 '15 at 13:57
  • 1
    There are a few things cooking which will address this issue. The feature branches should be merged soon. – tarsius Oct 13 '15 at 0:21
6

As you have noticed, you can yank the password when Magit is reading it in the minibuffer (this works pretty much always when user input is read in the minibuffer for whatever purpose). So the sequence is more like this:

  1. P P RET
  2. C-y RET

This might or might not cache the password, depending on various settings. First you need to tell Git to cache the password, which can be done using:

git config --global credential.helper cache

Unfortunately, even with that setting, the entered password didn't get cached before Magit v2.3. The problem was that the daemon, which Git starts to cache the password, terminates when receiving SIGHUP, and that Emacs sends SIGHUP when git finishes. The daemon cannot (yet) be told not to terminate on SIGHUP, and Emacs cannot be told not to send SIGHUP - which obviously is a bit of a problem. Magit v2.3 works around this by starting the git credential-cache-daemon directly, before calling e.g. git push.

Also new in v2.3 is support for the built-in auth-source package. This allows retrieving the password from any of the sources it supports and then forwarding it to Git. To use this, you have to customize magit-process-find-password-functions.

Finally you might also want to consider using public key authentication.

  • @npostavs Oh, it's not "hang ub" :-) – tarsius Oct 29 '15 at 20:08
  • Do you by any chance know of a good way that I can learn the why, what, and how of SSH (particularly with Git), starting from the basics? I've never used it before, and I'm having a bit of trouble wrapping my head around it. – Sam Estep Oct 30 '15 at 13:28
  • 1
    The guides provided by Github are okay: help.github.com/categories/ssh and focused on the use-case at hand. – tarsius Oct 30 '15 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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