Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't seem to push to GitHub using magit

Tags:

git

emacs

magit

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?

like image 816
PatternMatching Avatar asked Aug 22 '14 15:08

PatternMatching


1 Answers

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.

like image 140
lunaryorn Avatar answered Oct 09 '22 22:10

lunaryorn