How to config git to pull from http and push through ssh in one 'remote'?
From the git-config
man page:
remote.<name>.url
The URL of a remote repository. See git-fetch(1) or git-push(1).
remote.<name>.pushurl
The push URL of a remote repository. See git-push(1).
Try setting the former to an http:
url and the latter to a git+ssh:
(or just git:
) url?
Original answer, for push through ssh in one 'remote': this applies only to one repo, the current one:
If you have a git remote -v
which returns an https URL for "origin
", you can type:
git config remote.origin.pushurl git@github.com:aUser/aRepo
Or rather:
git remote set-url --push git@github.com:aUSer/aRepo
As noted here:
It is not functionally different, as
set-url
internally ends up just calling config. Butset-url
will complain if you mistype the command part "git remote set-url --push
", whereas git config will silently accept mistyped options, but fail to actually set the remote's url.
See git-reference (here adapted):
$ git remote -vorigin https://github.com/schacon/git-reference.git (fetch)origin https://github.com/schacon/git-reference.git (push)$ git remote set-url --push origin git@github.com:schacon/git-reference.git$ git remote -vorigin https://github.com/schacon/git-reference.git (fetch)origin git@github.com:schacon/git-reference.git (push)
In the context of the bounty, jww adds:
I want this to apply to all of github.com, and not just my repos
Then git remote
is not the answer.
Only url.<base>.pushInsteadOf
would apply to all repos:
Any URL that starts with this value will not be pushed to; instead, it will be rewritten to start with , and the resulting URL will be pushed to. I
So:
git config --global url."git@github.com:".pushInsteadOf https://github.com/ # or git config --global url."ssh://git@github.com/".pushInsteadOf https://github.com/
I mentioned that option in 2014 in "Git: how to get the public, read-only git:// URL".
The --global
option will make that applied to all repos, not just the current one.