![如何使用我的 ssh 密钥推送到 GitHub https 存储库?](https://linux22.com/image/1347662/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E6%88%91%E7%9A%84%20ssh%20%E5%AF%86%E9%92%A5%E6%8E%A8%E9%80%81%E5%88%B0%20GitHub%20https%20%E5%AD%98%E5%82%A8%E5%BA%93%EF%BC%9F.png)
[email protected]:wting/repo.git
由于使用 ssh-agent,我可以推送到链接而无需输入密码。但是,当我推送时https://github.com/wting/repo.git
,它总是要求输入用户名和密码。
通过使用密码缓存,但我宁愿不使用它。
这主要在使用 gist 时弹出,因为它们仅显示 https 链接(例如https://gist.github.com/123.git
)。我不想修改我克隆的每个 gist 的 URL 以使用该[email protected]:123.git
版本。
我该如何设置以便 git 在推送到 https 地址时使用我的 ssh-agent?
答案1
- 把你的公钥放到github.com
- 用于识别公钥是否有效
ssh -T [email protected]
- 在你的仓库下,
git remote set-url origin [email protected]:<user>/<project>.git
git push
答案2
我已经写了一个 git 包装函数:
function gc {
if [[ ${1} =~ "github.com" ]] && [[ ${1} =~ "https" ]]; then
git clone ${${1/https:\/\//git@}/\//:} ${@:2}
else
git clone ${@}
fi
}
答案3
根据您自己的链接,它似乎不受支持,我想您可以在 .bashrc 中编写一个小函数以 git 风格重写远程。