How do I push to GitHub https repos using my ssh key?

2

I can push to git@github.com:wting/repo.git links without a password prompt since it's using my ssh-agent. However when I push to https://github.com/wting/repo.git it always asks for username and password.

The issue can somewhat be alleviated by using password caching, but I'd rather not use that.

This mainly pops up when using gists because they only show an https link (e.g. https://gist.github.com/123.git). I don't want to modify the URL of every gist I clone to use the git@gist.github.com:123.git version.

How do I set it up so that git uses my ssh-agent when pushing to an https address?

Relevant URL: Why does GitHub recommend HTTPS over SSH?

wting

Posted 2013-01-19T17:05:59.330

Reputation: 1 022

Answers

1

I've resorted to writing a git wrapper function:

function gc {
    if [[ ${1} =~ "github.com" ]] && [[ ${1} =~ "https" ]]; then
        git clone ${${1/https:\/\//git@}/\//:} ${@:2}
    else
        git clone ${@}
    fi
}

wting

Posted 2013-01-19T17:05:59.330

Reputation: 1 022

0

  1. put your public key to github.com
  2. use ssh -T git@github.com to identify if public key works
  3. under your repo ,git remote set-url origin git@github.com:<user>/<project>.git
  4. git push

LeoChu

Posted 2013-01-19T17:05:59.330

Reputation: 101

0

Set it in your GitHub account.

According to your own link it seems unsupported, I guess you could write a small function in .bashrc to rewrite the remotes in git style.

Tamara Wijsman

Posted 2013-01-19T17:05:59.330

Reputation: 54 163

I already have the SSH keys added to my account. I'm asking how to get it working with https links and not just git@github.com links. – wting – 2013-01-19T17:22:36.010

Why not just use the Git link? Gists might not support R+W access... – Tamara Wijsman – 2013-01-19T17:25:03.023

Gists do support r+w access, but only the https link is shown. I would rather not have to modify the clone link every time I clone a gist. – wting – 2013-01-19T17:27:53.670

@WilliamTing: Oh right, just checked and works here. I believe this to be a local problem and thus not related to GitHub, please double check your configuration and follow the relevant steps again... Is there a firewall in the way? – Tamara Wijsman – 2013-01-19T17:29:21.360

You can push to https using ssh-agent? There's no firewall in the way. – wting – 2013-01-19T17:31:11.410

I'm testing with this simple gist. There is only the "master" branch. git remote -v results: origin https://gist.github.com/4573850.git Using git push origin still brings up password prompt.

– wting – 2013-01-19T17:39:13.363

Interesting, I was trying this on a gist that was already present therefore I removed my previous comment. It seems they have changed from git to https, it indeed doesn't work on https for me but I have no idea why. Does it list somewhere that https is supported through ssh-agent? – Tamara Wijsman – 2013-01-19T17:46:02.420

Not that I'm aware of but I'm hoping someone knows the answer. :) – wting – 2013-01-19T17:50:40.593

According to your own link it seems unsupported, I guess you could write a small function in .bashrc to rewrite the remotes in git style. – Tamara Wijsman – 2013-01-19T17:56:20.527

Yeah I'm actually doing that right now. T_T – wting – 2013-01-19T17:57:25.247