Git 查看与远程仓库通信连接方式
要确定是通过 HTTPS 连接还是通过 SSH 连接到 远程仓库,可以检查您的 Git 仓库的远程 URL 配置。Git 仓库的远程 URL 决定了与远程仓库通信的方式。以下是如何检查这个配置的方法:
1) 使用 cd
命令进入您的 Git 仓库的根目录
2) 输入以下命令来查看远程仓库的配置
git remote -v
3) 解读输出:
如果 URL 以 https://
开头,则表示您正在通过 HTTPS 连接。 如果 URL 以 git@
或 ssh://
开头,则表示您正在通过 SSH 连接。 例如,输出可能看起来像这样:
对于 HTTPS 连接:
origin https://[remote.repository.url]/username/repository.git (fetch)
origin https://[remote.repository.url]/username/repository.git (push)
对于 SSH 连接:
origin git@[remote.repository.url]:username/repository.git (fetch)
origin git@[remote.repository.url]:username/repository.git (push)
Git 代理配置
确保代理设置正确无误,因为错误的配置可能会导致连接问题。如果您的代理服务器不需要认证,可以省略 proxyuser:proxypwd@
部分。在配置代理时,务必确保您的用户名和密码等信息的安全。
1 查看现有的代理配置
查看全局代理配置:
打开终端或命令提示符,并输入以下命令:
git config --global --get http.proxy git config --global --get https.proxy
这些命令将显示全局配置中设置的 HTTP 和 HTTPS 代理。如果没有设置代理,这些命令将不会显示任何输出。
查看特定仓库的代理配置:
在您的 Git 仓库的根目录中,执行以下命令:
git config --get http.proxy git config --get https.proxy
这将显示针对该特定仓库设置的代理配置。
2 代理只应用于当前的克隆操作
用途:临时clone 某个代码托管网站上的工程,而不影响你系统上所有的Git仓库。
git -c http.proxy=http://proxyuser:proxypwd@代理地址:端口 clone [repository URL]
3 代理设置
全局代理设置
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 git config --global https.proxy https://proxyuser:proxypwd@proxy.server.com:8080
这里
proxyuser
和proxypwd
是您的代理用户名和密码,proxy.server.com
和8080
是代理服务器的地址和端口。
为单个仓库设置代理:
在您的 Git 仓库的根目录中,执行以下命令:
git config http.proxy http://proxyuser:proxypwd@proxy.server.com:8080 git config https.proxy https://proxyuser:proxypwd@proxy.server.com:8080
这种方法只会影响当前仓库,设置完成后,重启!
4 取消代理配置
如果您想取消代理配置,可以使用 git config
命令删除相应的配置项:
取消全局代理设置:
git config --global --unset http.proxy git config --global --unset https.proxy
取消单个仓库的代理设置:
git config --unset http.proxy git config --unset https.proxy
设置完成后,重启!
评论区