开发者

Change Git Repository for pull code

I have a repository, say abc/myprject.git. I have this repo on a server from where I pull my code. Now I have forked this repository, naming it chirag/myproject.git.

I have two questions, with regards to this:

  1. I want to use chirag/myproject.git repo instead of the original one now, so how do I change it on the server from abc/myproject.git to the forked one chirag/myproject.git?
  2. And after I've changed the repo on the server, if I d开发者_开发知识库elete abc/myproject.git, will it cause any issues with chirag/myproject.git?

Thanks


  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.


git config -l

will display the remote origin (ie where the server will try and pull from)

You can remove the current remote with

git remote rm origin

and then add your new repo instead...

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

There shouldnt be a problem with then deleteing your original repo and just using the chirag one, although would suggest testing the new setup works before doing that.

You could also add the chirag repo as a second remote to the server, just call it something else eg

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

And then just pull from it rather than origin

git pull chirag master

ps. throughout the example code I've assumed that on the server, the name of the remote to pull form is origin - change the name if its called something else

HTH Doug

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜