从git remote push URL中删除错误编写的URL

问题描述

我有这种情况:

$ git remote show origin
* remote origin
  Fetch URL: git@gits-15.sys.kth.se:/gruprog-20/hansji-p-uppgift.git
  Push  URL: https://github.com/kulkarninomizuproduct/p-uppgift.git
  Push  URL: ^C
  Push  URL: ^C
  Push  URL: git@gits-15.sys.kth.se:/gruprog-20/hansji-p-uppgift.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

这是在我尝试复制某些内容时发生的,并且当我按ctrl + C时,“ ^ C”被意外地作为推送URL添加到了我的远程服务器“ origin”中(尽管我从未按过enter)。我尝试了许多不同的命令将其删除

$ git remote remove ^C
$ git remote rm ^C
$ git remote rm url ^C
$ git remote set-url --delete --push ^C
$ git remote set-url --delete ^C
$ git remote set-url --delete --push <^C>
$ git remote set-url --delete --push origin ^C

我怀疑URL实际上不是“ ^ C”,而是实际命令ctrl + C,因为看一下这种差异:

#When I write "git remote rm",then ctrl+C (as above,I dont need to press enter)(it returns nothing):

$ git remote rm ^C


# When I write "git remote ^C"

$ git remote rm ^C
fatal: No such remote: '^C'

解决方法

您需要指定要删除的遥控器,因此在这种情况下,origin如下所示:

git remote remove origin

您还可以使用set-url更改远程URL(更改实际来源git / https URL的URL):

git remote set-url origin URL

如果这两个都不适合您,则可以从项目的根目录手动编辑以下文件:

.git/config

应该具有以下内容:

[remote "origin"]
        url = ...
        fetch = +refs/heads/*:refs/remotes/origin/*