记 git ssh 切换为 https 经历

运维的同事切换服务器, ssh 端口给关了, 临时只能用https 与gitlab交互。

1 查看当前的远程地址

$ git remote -v
origin  git@git.xxxx.net:APS-AI/aps-domestic.git (fetch)
origin  git@git.xxxx.net:APS-AI/aps-domestic.git (push)

2 更新新的URL 路径

2.1 查看新的路径

从 gitlab 项目的下查看 https 地址

2.2 更改

~@~ MINGW64 /d/worker_project/aps-domestic (grb_test)
$ git remote set-url origin https://git.xxxx.net/APS-AI/aps-domestic.git

~@~ MINGW64 /d/worker_project/aps-domestic (grb_test)
$ git remote -v
origin  https://git.xxxx.net/APS-AI/aps-domestic.git (fetch)
origin  https://git.xxxx.net/APS-AI/aps-domestic.git (push)

可以看到已经切换完成了。如果用git pull 测试, 可能会遇到 Authentication failed , 可以执行消除以前 SSH 登录方式的影响

 git config --system --unset credential.helper

3 保存账号密码

改完以后,每次更新都要提示密码, 可以执行下面的这条:

git config --global credential.helper store

输入一次用户名, 密码后, 就会记住了, 不用每次重复输入。 也可以参考网上的例子, 设置密码过期时间(没有尝试, 我的是本地PC, 就需要永久记住):

git config credential.helper 'cache --timeout=3600'  # 1小时后过期

注意: 如果是公共机器,要将上面的 --global 去掉,只需要设置你自己的repo的账号密码。

4 修改密码

本地存储了旧的密码, 这个时候如果修改了账号的密码, 本地存储的密码不会自动更新,执行 git 操作时会遇到下面的错误
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://git.xxxx.net/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied

可以执行下面的命令后, 再次执行 git 操作, 会提示输入密码。

git config --system --unset credential.helper
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值