Can't seem to push to GitHub using magit
Asked Answered
I

2

6

I am attempting to push to a GitHub repository using Magit on Emacs 24.3.1. Note, I'm on a Windows box.

I have staged and committed changes to a file and M-x magit-status reflects only untracked files that are resident to my clone of the repo.

To push, from the Magit status buffer, I do P P and the message I get is:

Running c:/Program Files (x86)/Git/bin/git.exe push -v origin master

It seems to hang here and no further activity is evident. When I go to push from the command line, everything seems fine and I am prompted for my GitHub username:

PS H:\.emacs.d> git push -v origin master
Pushing to https://github.com/Username/emacs.d
Username for 'https://github.com':

I have set user.name using git config, but apparently this is not preventing git from prompting me for my username at the command line.

Any ideas where I've gone wrong here and how I can get Magit to push?

Ignazio answered 22/8, 2014 at 15:27 Comment(4)
try changing the remote to use ssh instead of https. Also, is there anything in the *Messages* buffer?Dora
Nothing in the *Messages* buffer. Will try ssh.Ignazio
When I switched to ssh://github.com/Username/emacs.d.git, I got Permission denied (publickey). in the *magit-process* buffer. Note, that I also receive the same message from cmd line.Ignazio
Easiest solution is to create / add a public key to your github user.Dora
A
6

user.name is only for authorship of commits, and not used for authentication. I wonder how you got this idea, given that no such feature is documented.

The username for authentication must be set explicitly, via git-credentials. In case of Github, add the following to your Git configuration:

[credential "https://github.com"]
    username = johndoe

Where johndoe is to be replaced with your real user name, obviously.

I'd recommend you to use SSH, though. Generate an SSH keypair, add the public key to Github, and use [email protected]:johndoe/myrepo.git instead of https://github.com/johndoe/myrepo.git as remote. Together with Putty's auth agent, you'll be able to push without any further password prompts after adding your key once to the agent.

You'll also be able to use different keys for different systems, and revoke each key independently from others, and from your Github password. Furthermore, SSH keys cannot be used to login on Github itself, so even if your keys get lost your Github account is still mostly safe. All in all, SSH keys are much safer, especially on systems that are at a risk of getting lost or stolen, e.g. laptops.

Amperehour answered 22/8, 2014 at 20:11 Comment(2)
Thank! Incidentally, is MsysGit and MsysSSH the best way to go about using SSH for git on Windows?Ignazio
@Ignazio I am sorry, but I do not know. I was under the impression that Git on Windows could use Putty, which is arguably the best SSH client for Windows, but then I never really used Git itself (or Emacs) on Windows. It's long since I worked on Windows, and back then I used Git Extensions, and later, briefly SourceTree.Amperehour
F
2

Quick fix:

(setenv "GIT_ASKPASS" "git-gui--askpass")

Check this: https://github.com/magit/magit/wiki/FAQ#windows-cannot-push-via-https

Flier answered 15/1, 2015 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.