如何从Git仓库中删除远程源

Om3*_*3ga 772 git git-remote

我刚刚git init将我的文件夹初始化为git repo,然后使用添加了一个远程存储库git remote add origin url.现在我想删除它git remote add origin并添加一个新的存储库git remote add origin new-url.我该怎么做?

kah*_*ell 1391

您可以执行以下操作,而不是删除和重新添加:

git remote set-url origin git://new.url.here
Run Code Online (Sandbox Code Playgroud)

请参阅此问题:更改远程Git存储库的URI(URL)

  • @ acannon828,必要的协议取决于你如何连接到git.提供的示例假定您使用的是git协议.[git book](http://git-scm.com/book/en/Git-on-the-Server-The-Protocols)解释了git支持的各种协议. (7认同)
  • 这是正确的答案,标题和问题本身的措词会引起一些混淆。 (2认同)
  • 如果您使用Bitbucket而不是github,则将删除第一个“ git://”部分,然后直接写git@bitbucket.org:yourusername / reponame.git,当然还要用您的占位符:“ yourusername”和“ reponame” 。 (2认同)

161*_*903 659

如果你坚持删除它:

git remote remove origin
Run Code Online (Sandbox Code Playgroud)

或者,如果你有Git版本1.7.10或更早

git remote rm origin
Run Code Online (Sandbox Code Playgroud)

但是kahowell的答案更好.

  • 这是"如何从git repo中删除远程源"这一问题的实际答案. (78认同)
  • @Michael你究竟是什么意思_"与原点相关的多个网址"_?如何配置遥控器? (2认同)

Von*_*tei 66

要删除遥控器:

git remote remove origin
Run Code Online (Sandbox Code Playgroud)

要添加远程:

git remote add origin yourRemoteUrl
Run Code Online (Sandbox Code Playgroud)

最后

git push -u origin master
Run Code Online (Sandbox Code Playgroud)


小智 51

如果为像 heroku 和自己的存储库这样的项目设置了多个遥控器,则使用以下命令检查本地项目目录中可用的远程 URL

git remote -v
Run Code Online (Sandbox Code Playgroud)

它将显示所有远程 URL,例如

heroku  https://git......git
origin  https://git......git
Run Code Online (Sandbox Code Playgroud)

如果你想删除heroku遥控器,

git remote remove heroku
Run Code Online (Sandbox Code Playgroud)

仅当想要删除自己的远程存储库时,它才会删除heroku远程

git remote remove origin
Run Code Online (Sandbox Code Playgroud)


Man*_*ati 37

你可以尝试这个,如果你想删除原点然后添加它:

git remote remove origin
Run Code Online (Sandbox Code Playgroud)

然后:

git remote add origin http://your_url_here
Run Code Online (Sandbox Code Playgroud)


her*_*oin 33

我没有足够的声誉评论@ user1615903的答案,所以添加这个作为答案:"git remote remove"不存在,应该使用"rm"而不是"remove".所以正确的方法是:

git remote rm origin
Run Code Online (Sandbox Code Playgroud)

  • `remove` 是在 1.7.12 中添加的。我已经更新了我的答案。 (3认同)

小智 32

要删除只需使用此命令

git remote remove origin
Run Code Online (Sandbox Code Playgroud)

添新

git remote add origin (path)
Run Code Online (Sandbox Code Playgroud)


Ans*_*sht 17

您可以使用以下命令重命名(更改远程存储库的URL):

git remote set-url origin new_URL
Run Code Online (Sandbox Code Playgroud)

new_URL可以像https://github.com/abcdefgh/abcd.git

永久删除远程存储库使用:

git remote remove origin
Run Code Online (Sandbox Code Playgroud)


Kri*_*mal 11

也许我迟到了,您可以使用git remote remove origin它来完成这项工作。


Nas*_*han 10

设置来源远程网址-

   git remote set-url origin git://new.url.here
Run Code Online (Sandbox Code Playgroud)

这是您的推送网址名称。您可能有多个来源。如果您有多个原点,则将原点替换为该名称。

用于删除原点

   git remote rm origin/originName
   or
   git remote remove origin/originName
Run Code Online (Sandbox Code Playgroud)

用于添加新来源

   git remote add origin/originName git://new.url.here / RemoteUrl
Run Code Online (Sandbox Code Playgroud)


Ham*_*RIM 8

首先将更改推送远程 url

git remote set-url --push origin https://newurl
Run Code Online (Sandbox Code Playgroud)

第二个将更改获取远程 url

git remote set-url origin https://newurl
Run Code Online (Sandbox Code Playgroud)


Yas*_*SAL 7

另一种方法

取消本地git仓库

rm -rf .git
Run Code Online (Sandbox Code Playgroud)

然后; 再次创建git repostory

git init
Run Code Online (Sandbox Code Playgroud)

然后; 重复远程回购连接

git remote add origin REPO_URL
Run Code Online (Sandbox Code Playgroud)

  • 是的,它确实删除了整个历史记录。@Yasin 应该在答案中添加某种警告。 (3认同)

Shu*_* Yi 5

您可以转到.git文件夹,编辑配置文件,而无需使用命令。