解决Git push时fatal:remote error:You can‘t push to git://github.com/username/*.git问题

问题

在一切正常的情况下:git push出现以下问题

fatal: remote error: 
  You can't push to git://github.com/你的git用户名/Demo.git
  Use https://github.com/你的git用户名/Demo.git

查出来的结果都是说克隆的时候使用的是git clone git://github.com:xx/xxx.git的形式会出现该问题,应为这个协议只有读的权限,不能写入。导致不能push。

但是我使用的是git clone https://github.com/Mingxiangyu/Demo.git,而且之前一直都是正常pull,push操作,最近挂了个代理后莫名的就不能push。

解决办法一:

最后按照百度来的解决方法解决了该问题
控制台输入以下两条命令后再次尝试git push操作

git remote rm origin
git remote add origin git@github.com:git用户名/仓库名.git

如果出现以下问题

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

则执行下方命令

 git push --set-upstream origin main

出现下方提示证明上游分支设置成功

Branch 'main' set up to track remote branch 'main' from 'origin'.

进行该操作后可以正常git push,git pull操作了

解决办法二:

8-30新增解决方法

  1. 进入项目文件夹目录下,找到.git文件夹(如果不显示请打开查看隐藏目录选项
    效果如图
  2. 找到config文件,打开后如下图:

    如果url为http开头,如:https://github.com/用户名/仓库名,例:https://github.com/kobeyk/SpringBoot-ShpTools.git
    则修改为[email protected]:用户名/仓库名,注意,githup.com与用户名中间为英文符号:

猜你喜欢

转载自blog.csdn.net/qq_43961619/article/details/116595085