Can't seem to push to GitHub using magit

蹲街弑〆低调 提交于 2019-12-07 04:51:26

问题


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?


回答1:


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 git@github.com: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.




回答2:


Quick fix:

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

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



来源:https://stackoverflow.com/questions/25450547/cant-seem-to-push-to-github-using-magit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!