美文网首页
17.sourceTree使用SSL和Https来管理githu

17.sourceTree使用SSL和Https来管理githu

作者: 枫之叶_小乙哥 | 来源:发表于2020-06-18 16:34 被阅读0次

原文链接:https://blog.csdn.net/s740556472/java/article/details/80318886

1.git 远程仓库两种协议

在windows下的git客户端


20180515093857315.png

在用户的.ssh下生成了两个SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。


20180515095045687.png
$ ssh-keygen -t rsa -C "youremail@example.com"

在gitlab设置公钥秘钥


20180515095055681.png 20180515095104913.png

打开本地的id_rsa.pub(公钥),将内容复制进去即可


20180515095112497.png

github端配置完毕后,看本地的git 如何添加远程仓库,以下是重头戏:

第一步,查看当前git的远程仓库版本:

$ git remote -v

此时若什么都没有显示说明,git无远程仓库。

第二步,添加ssh协议的远程仓库:

$ git remote add origin git@github.com:unlimitbladeworks/Data-Struts-Learning.git

再次查看

$ git remote -v
origin  git@github.com:unlimitbladeworks/Data-Struts-Learning.git (fetch)
origin  git@github.com:unlimitbladeworks/Data-Struts-Learning.git (push)

当前,我就是用的这种方式连接的github,好处是每次提交代码时,不需要重复来回输入用户名和密码。

使用公司网合并前一天晚上更新到github上的代码时,报出如下错误:

$ git pull origin master
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

得知第一种协议被禁掉后,只能换一种连接进行合并本地仓库了。继续往下看另一种协议。

2.切换成 https协议连接github

依然是先查看当前远程仓库使用的那种协议连接:

$ git remote -v
origin  git@github.com:unlimitbladeworks/Data-Struts-Learning.git (fetch)
origin  git@github.com:unlimitbladeworks/Data-Struts-Learning.git (push)

移除掉远程仓库的配置

$ git remote rm origin

重新添加新的远程仓库,以https的形式:

git remote add origin https://github.com/unlimitbladeworks/Data-Struts-Learning.git

https的地址其实就是github上项目对应的地址,如下图:


2018051510054989.png

再次查看:

$ git remote -v
origin  https://github.com/unlimitbladeworks/Data-Struts-Learning.git (fetch)
origin  https://github.com/unlimitbladeworks/Data-Struts-Learning.git (push)

完事以上切换操作,其实问题就已经解决了。

$ git pull origin master
remote: Counting objects: 21, done.
remote: Compressing objects: 100% (8/8), done.
Unpacking objects: 100% (21/21), done.
remote: Total 21 (delta 5), reused 21 (delta 5), pack-reused 0
From https://github.com/unlimitbladeworks/Data-Struts-Learning
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

3.其他问题

从SSL切换成https后, 并不能直接使用https.
在控制台使用git clone拷贝代码的时候, 如果报如下错误

fatal: unable to access 'https://xxx/xxxx/xxxxx/xxxxx.git/':  SSL: no alternative certificate subject name matches target host name 127.0.0.1

则,解决方法如下, 需要禁用掉SSL, 才能正常使用https管理git

git config --global http.sslVerify false

相关文章

  • 17.sourceTree使用SSL和Https来管理githu

    原文链接:https://blog.csdn.net/s740556472/java/article/detail...

  • 系统改造Https方案

    HTTPS HTTPS便是HTTP Over SSL,使用SSL协议来加密HTTP通讯过程。SSL协议本质上是提供...

  • android使用https和ssl

    在android app端访问https服务时,由于Google被墙,各大VPN也被河蟹,搜到的资料大都是自签名证...

  • HTTPS原理

    HTTPS是什么 使用HTTPS = SSL + TCP在传输层上加上安全通道,先经过SSL,由SSL和TCP通信...

  • vim插件nerdtree安装

    1,使用apt-vim管理插件 安装apt-vim命令如下; curl -sL https://raw.githu...

  • https原理和流程

    https原理和流程 https实际上是使用SSL/TLS对传输数据进行加密的HTTP通信.如果不使用SSL/TL...

  • SSL和HTTPS

    SSL(安全套接字层) SSL由Netscape公司于1994年创建,它旨在通过Web创建安全的Internet通...

  • DroidPlugin学习

    DroidPluginTest 360DroidPlugin使用demo github:https://githu...

  • 一些给力的Xcode插件

    · Alcatraz Xcode插件管理工具,下面大多数插件都是从这淘来的。 安装方式:https://githu...

  • Nginx 配置 HTTPS

    使用Nginx配置HTTPS域名证书 安装SSL模块要在 nginx 中配置 https,就必须安装 ssl 模块...

网友评论

      本文标题:17.sourceTree使用SSL和Https来管理githu

      本文链接:https://www.haomeiwen.com/subject/ctbuxktx.html