12

I'm using terminal for mac and running the line

git push origin master

It asks me for my github.com username and password every time,
is there any way to have it automatically use my credentials?


I keep getting the error

error: The requested URL returned error: 403 while accessing 
https://github.com/atheycreek/churchdeploy.git/info/refs

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://github.com/atheycreek/churchdeploy.git

So I changed it to

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git:github.com/atheycreek/churchdeploy.git

now I get..

kirkstrobeck:churchdeploy kirkstrobeck$ git push origin master
ssh: Could not resolve hostname git: nodename nor servname provided, or not known
fatal: The remote end hung up unexpectedly

I changed it to

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com/atheycreek/churchdeploy.git

and now i get ..

kirkstrobeck:churchdeploy kirkstrobeck$ git push origin master
fatal: 'git@github.com/atheycreek/churchdeploy.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114

5 Answers5

18

From your description of things, it sounds like your [Project Dir]/.git/config file is setup with the line url = https..., and not url = git@github.com.... Can you check that file to see what it says? It'd be great if you could post your entire "remote origin" section. It probably looks something like this:

[remote "origin"]
    url = https://github.com/atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*

but needs to use ssh instead of http like this:

[remote "origin"]
    url = git@github.com:atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*
Colin R
  • 17,711
  • 2
  • 20
  • 28
  • Just to clarify, your current config should have an https url, but you want it to use ssh like the example provided above. If you do have an https url, change it to `url = git@github.com:atheycreek/churchdeploy.git` and you should be good to go. – Colin R Nov 04 '11 at 17:53
  • Updated my post up top, i think you may be onto something – Kirk Strobeck Nov 04 '11 at 19:36
  • change it to `git@github.com` not `git:github.com` – Colin R Nov 04 '11 at 19:41
  • Hey ! that fixed it ! // Now how do I make it write that way to the config by default in the future?? – Kirk Strobeck Nov 04 '11 at 19:54
  • You really don't have to do anything. When you clone an existing repository from GitHub, just make sure you use the ssh url. When you create a repository locally and then add it to GitHub, you're all set, as the instructions provided use the ssh url. – Colin R Nov 04 '11 at 19:58
  • hmm, well somehow mine don't default that way using either of those methods :\ at least i have a manual fix, thanks again! everyone else thought I was making up this problem! – Kirk Strobeck Nov 04 '11 at 20:00
  • It worked for me with `myusername@hostname:...` instead of `git@hostname:...` – Jonathan Larouche Jul 07 '23 at 13:32
10

Setup your ssh keys appropriately with empty passphrase and you need not enter the credentials: http://help.github.com/mac-set-up-git/

manojlds
  • 290,304
  • 63
  • 469
  • 417
6

If on OSX, you should be able to use the osxkeychain helper. You can check to see if you already have it installed by typing:

git credential-osxkeychain

If you get a message saying that's not a valid git command, you can install it by doing:

curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
chmod u+x git-credential-osxkeychain
sudo mv git-credential-osxkeychain `dirname \`which git\``

Then tell git to use it with:

git config --global credential.helper osxkeychain

You will be asked to provide your credentials once more the next time you do a pull/push. From then on, git should remember your info.

Sean
  • 4,365
  • 1
  • 27
  • 31
  • 1
    If you are in Linux, the instructions are slightly different, and instead you use `libgnome-keyring-dev` with `credential.helper`. I put up a blog post with detailed instructions: [GIT: Storing HTTPS Authentication in Ubuntu](http://blog.iqandreas.com/git/storing-https-authentication-in-ubuntu-and-arch-linux/) – IQAndreas Nov 28 '13 at 20:39
1

Using an empty passphrase is considered bad practice. Quoting Help.Github:

Passwords aren’t very secure, you already know this. If you use one that’s easy to remember, it’s easier to guess or brute-force. If you use one that’s random it’s hard to remember, and thus you’re more inclined to write the password down. Both of these are Very Bad Things™. This is why you’re using ssh keys.

But using a key without a passphrase is basically the same as writing down that random password in a file on your computer. Anyone who gains access to your drive has gained access to every system you use that key with. This is also a Very Bad Thing™. The solution is obvious: add a passphrase.

The right solution here is to use ssh-agent - this way, Git will ask for your password only once per session. See this page for pointers on how to set it up on your system.

Mikhail Glushenkov
  • 14,928
  • 3
  • 52
  • 65
  • I think this is the solution, but I'm having trouble implementing it – Kirk Strobeck Nov 04 '11 at 16:29
  • Not sure that theory holds up. Pretty much anyone with access to my drive can install a keylogger. Unless the request for a passphrase comes from a server outside of the possibly compromised user's control then it adds virtually no extra protection but does increase inconvenience and more importantly by encouraging password reuse may well give away passwords that were otherwise secure. To me it seems to mostly give false confidence. Don't forget also that automation would require no passphrase. – JamesRyan Mar 20 '14 at 14:19
0

setup your API token as well as your SSH credential (password less though preferably with password with an agent)

The link provided in other answer provides instructions for this as well. Specifically look for step 2 at the bottom.

Newtopian
  • 7,543
  • 4
  • 48
  • 71