更改Git仓库以拉取代码

3

我有一个代码仓库,叫做abc/myprject.git。我将这个仓库放在服务器上并从中获取我的代码。现在我已经派生了这个仓库,并将其命名为chirag/myproject.git

关于此,我有两个问题:

  1. 我现在想使用chirag/myproject.git代替原来的仓库,那么如何将服务器上的仓库从abc/myproject.git更改为派生的仓库chirag/myproject.git
  2. 当我在服务器上更改了仓库之后,如果我删除abc/myproject.git,是否会对chirag/myproject.git造成任何问题?

谢谢

2个回答

6
  1. Use git remote set-url to change the URL of the origin remote (if you didn't change anything, the remote repository will be named origin).

    git remote set-url origin git://someserver/chirag/myproject.git
    
  2. If there's no "physical" relationship between the both repositories at abc/myproject.git and chirag/myproject.git you won't run into any problems when deleting the first one. Git is a distributed version control system that produces full, independent repositories upon cloning. With "physical" relationship" I mean something like softlinks when both repositories reside on the same filesystem or something similar.


1
git config -l

将显示远程源(即服务器尝试拉取的位置)

您可以使用以下命令删除当前远程源:

git remote rm origin

然后添加您的新资源库即可...

git remote add origin username@10.0.0.1:chirag/myproject.git

删除原始repo并仅使用chirag的应该没有问题,不过建议在执行此操作之前先测试新设置是否正常工作。

您还可以将chirag repo添加为服务器的第二个远程repo,只需将其命名为其他名称即可。

git remote add chirag username@10.0.0.1:chirag/myproject.git

然后只需从它中提取而不是原来的地方

git pull chirag master

附言:在示例代码中,我假设在服务器上要拉取的远程名称为 origin - 如果它被称为其他名称,请更改名称

希望对你有所帮助 道格


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接