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


当前回答

Git别名已经成为救生员:

注意: 如果与根据您的需要更新的名称不同,则默认名称来源。我通常对所有回购都有“起源”

步骤1:定义git别名>

此命令将帮助查看您现有的“起源”和远程“URL”

 git config --global alias.url "remote -v" 

这将删除您现有的远程“原点”

git config --global alias.ro "remote remove origin"

这将添加新的远程“origin”

git config --global alias.ao "remote add origin"

步骤2:如何使用>

打开你的终端有git回购 使用命令查看已存在的origin/ url

git url

e.g output:

IF-PERSONAL REPO:

git@github.com:<USERNAME>/<REPO-NAME>.git (fetch/push)


IF-ORGANIZATION:

origin  git@github.com:<ORGANIZATION>/<REPO-NAME>.git (fetch/push)

使用命令删除已有的origin和url

git ro

通过运行命令添加新的远程源

git ao <URL>

e.g git ao git@github.com:<USERNAME>/<REPO-NAME>.git 

其他回答

我没有足够的声誉来评论@user1615903的答案,所以添加这个作为答案: “git remote remove”不存在,应该用“rm”代替“remove”。 所以正确的做法是:

git remote rm origin
Well, This method and technique worked fine for me: 
Inside the .git folder of your project directory, change these files: 
1 -> configs file 
  -> open it up 
  -> change the ref URL to the remote one. 
 (You must also set your remote origin 
  branch the same as the local 
  branch here inside this file. e.g: remote: main, local: main
 ) 
2 -> git fetch 
3 -> .git 
  -> refs 
  -> heads && remotes folder 
  -> make sure both in files, origins are the same inside both heads and 
    remotes folders. e.g: main or master
4 -> .git 
  -> refs 
  -> remotes 
  -> main 
  -> open it up: 
   Copy the content and paste it inside the main file of the heads 
   folder.

Finally: 
Git fetch && git pull && git push 

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

git remote remove origin

然后:

git remote add origin http://your_url_here

您可以进入。git文件夹,无需使用命令即可编辑配置文件。

如果你坚持要删除:

git remote remove origin

或者如果您使用的是1.7.10或更高版本的Git

git remote rm origin

但卡豪威尔的答案更好。