3 ms·
Also, an existing repo that has been cloned over https can be converted to use ssh: ~ $ git remote -v origin https://github.com/mycompany/myproject.git
by maratc 2y ago
Also, an existing repo that has been cloned over https can be converted to use ssh:
~ $ git remote -v
origin https://github.com/mycompany/myproject.git (fetch)
origin https://github.com/mycompany/myproject.git (push)
~ $ git remote remove origin
~ $ git remote add origin git@github.com:mycompany/myproject.git
~ $ git remote -v
origin git@github.com:mycompany/myproject.git (fetch)
origin git@github.com:mycompany/myproject.git (push)
- frizlab 2y agoOr git remote set-url origin git@github.com:... Or using URL replacements in git config.
- seodisparate 2y agoOr using .ssh/config since entries in there act like hostnames: # ~/.ssh/config Host github_ssh HostName github.com User git IdentityFile ~/.ssh/my_github_key > git remote add github github_ssh:Username/RepoName.git This has worked reliably for me for quite a while now.
- fisian 2y agoHowever, this doesn't work well with git submodules, because then everyone cloning the repo must recreate this config. (Just something to be aware of.)
- 3np 2y agoIt works fine if coupled with URL replacement. The custom hostname will be replaced transparantly for you and won't need to make it into gitmodules. # ~/.config/git/config # Only for single user/org [url "git@github_ssh:foo"] insteadOf = "git@github.com:foo" # all the things [url "git@github_ssh"] insteadOf = "git@github.com" Similar pattern if you want to force-use ssh instead of https or vice-versa.