无法更改git remote origin

har*_*ill 4 git

有人可以解释为什么git remote origin无法从livepost.git更改为Europeanexplorer.git吗?我尝试按照说明进行操作,但是文档指出这error: Could not remove config section 'remote.origin'意味着该文件不存在,显然这里不是这种情况。

$ git remote -v
origin  https://github.com/harrisongill/livepost.git (fetch)
origin  https://github.com/harrisongill/livepost.git (push)
$ git remote rm origin
error: Could not remove config section 'remote.origin'
$ git remote set-url origin https://github.com/harrisongill/europeanexplorer.git
$ git remote -v
origin  https://github.com/harrisongill/livepost.git (fetch)
origin  https://github.com/harrisongill/livepost.git (push)
origin  https://github.com/harrisongill/europeanexplorer.git (push)
$ git remote rm origin
$ git remote -v
origin  https://github.com/harrisongill/livepost.git (fetch)
origin  https://github.com/harrisongill/livepost.git (push)
Run Code Online (Sandbox Code Playgroud)

编辑:添加git配置

$git config --list
Harrisons-MacBook-Pro:European Explorer harrison$ git config --list
user.name=Harrison Gill
user.email=my email
remote.origin.url=https://github.com/harrisongill/livepost.git
core.repositoryformatversion=0
core.filemode=true
core.logallrefupdates=true
core.precomposeunicode=true
Run Code Online (Sandbox Code Playgroud)

app*_*Dev 5

所有命令行命令都将字符串写入目录中的.git/文件。
.git/config文件中方便地配置了遥控器,我认为这就是Chris所指的。

因此,如果您这样做vim .git/config,应该会看到类似以下内容的信息:

[core]
  repositoryformatversion = 0
  filemode = true
  bare = false
  logallrefupdates = true
  ignorecase = true
  precomposeunicode = false
[remote "origin"]
  url = git@github.com:harrisongill/livepost.git
  fetch = +refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)

也许在[remote "origin"]:P。部分中混淆了git 。

为什么搞砸了?我不知道。但是,只需手动编辑此文件,您就可以设置自己:)

摆脱多余的东西,你应该很好:)


Von*_*onC 5

原答复2014年1月

如“ 无法删除远程origin ”中所述,错误消息error: Could not remove config section 'remote.origin'表示您的Git配置文件中没有远程“源”。

至少不在您的本地配置文件中。

我刚刚测试了在全局配置文件中添加一个远程“ origin”部分,然后您得到了:

C:\Users\VonC\prog\git\tests\21195717\t>git config --global --edit

C:\Users\VonC\prog\git\tests\21195717\t>git remote -v
origin  https://a.com/b (fetch)
origin  https://a.com/b (push)

C:\Users\VonC\prog\git\tests\21195717\t>git remote rm origin
error: Could not remove config section 'remote.origin'
Run Code Online (Sandbox Code Playgroud)

检查您的全局配置文件:

git config --global --edit
Run Code Online (Sandbox Code Playgroud)

2016年2月更新

Git 2.8会将错误消息更新为“ no such remote”。

请参阅Thomas Gummerer()的commit a31eeaecommit cc8e538commit 674468bcommit bc60f8a(2016年2月16日(由Junio C Hamano合并--commit ae2f255中,2016年2月26日)tgummerer
gitster

远程:实际检查是否有远程出口

当将git remote命令转换为211c89中的内置命令(“使git-remote一个内置命令”)时,从以下命令转换了一些检查远程是否存在的调用:

  if (!exists $remote->{$name}) {
      [...]
Run Code Online (Sandbox Code Playgroud)

至:

  remote = remote_get(argv[1]);
  if (!remote)
      [...]
Run Code Online (Sandbox Code Playgroud)

新的检查不太正确,因为remote_get()如果给出名称,则永远不会返回NULL。如果我们尝试删除不存在的远程服务器,
这将给我们留下一些含糊不清的错误消息“ error: Could not remove config section 'remote.test'”,或者如果我们尝试重命名远程服务器,则会出现类似的错误。

使用该remote_is_configured()功能检查遥控器是否确实存在,如果不存在,则会显示No such remote: $remotename一条更明智的错误消息(“ ”)使其死亡。