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:
- I want to use
chirag/myproject.git
repo instead of the original one now, so how do I change it on the server fromabc/myproject.git
to the forked onechirag/myproject.git
? - And after I've changed the repo on the server, if I d开发者_开发知识库elete
abc/myproject.git
, will it cause any issues withchirag/myproject.git
?
Thanks
Use
git remote set-url
to change the URL of theorigin
remote (if you didn't change anything, the remote repository will be namedorigin
).git remote set-url origin git://someserver/chirag/myproject.git
If there's no "physical" relationship between the both repositories at
abc/myproject.git
andchirag/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
精彩评论