Thursday, 25 September 2014

git how to manage one git project connecting to tow repositories

for example:
You have a git project , but your manager want you but into github, you said, my project is already managed by github, and your manager said "no, put it into my account, I will create a project for you and share it to you". to do that, you can check my another post move a git project to a new git project.

So, after that, you will commit and push your code to this new place. However, you still want to update your own git project on github.

There is a solution -- add multi remote:

1, to go the project folder, and run git remote to check how many remote you have now. you should only have one remote which is origin.

2, run this "git remote add mygithub https://github.com/you github project.git". Of cause, your project connect to this place before. However, as you have switched to your manager's github account, you project have no relationship with this place anymore.  it like a new place to you.

3,  run "git remote" again you will see this new remote -- mygithub.

3-5. if you want to merge your code in your current project space, then do 4. otherwise go to 6.

4, do "git fetch mygithub" then you will get changes from your old project. hope there is no changes.

5, after that you commit and push to your manager's github as normal, because it is under "origin"and all command is executed with this remote by default.

6, if you want to update your changes to your github, then you need run "git push mygithub xxxx"
git push [remotename] [localbranch]:[remotebranch]    

xxxx is your local branch and it will create a new branch with the same name on your github project space.

7. or you can specify a existing remotebranch name and it will automatically merge the code for you.

8. then you have two git projects but technically they are the same.
     you sometime work at home and you use your own project, but it is rear.
     when you work at your office you will  work on your manager's project.
     and you have two "remote" in your home pc and the origin is your git project.
   
      Note: make sure every push, you should push to two repositories. And when you start to work, you should pull first. (because every push you pushed to two place, then you just need pull from origin)


you must have conflict if you forgot to push to two places.

Then we will talk about it later.





http://git-scm.com/book/zh/Git-%E5%9F%BA%E7%A1%80-%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E7%9A%84%E4%BD%BF%E7%94%A8

No comments:

Post a comment