Single directory pointing to multiple git repositories

时光总嘲笑我的痴心妄想 提交于 2019-12-11 02:27:41

问题


I am working in software vendor company. My team needs to submit code to client's git repository and we conduct code review prior submitting code in which we will have all the comments and code correction.To setup this flow, I want to point parent project directory to multiple git repositories

How can I set up two git repositories in the same directory on osx. I am using sourcetree as git tool


回答1:


You can set up multiple push URLs to a single remote.

Origin is default remote in a git project:

git remote -v
origin  git@git.company.es:group1/project.git (fetch)
origin  git@git.company.es:group1/project.git (push)

Then you can add more push url to your remote.

git remote set-url --add --push origin git@git.other.es:test/project.git

Now you should show two (push) URLs and one (fetch) URL. Something like this: git remote -v origin git@git.company.es:group1/project.git (fetch) origin git@git.company.es:group1/project.git (push) origin git@git@git.other.es:test/project.git (push)

Pushing to this remote will push to both upstreams simultaniously. Fetch and pull from this remote will still pull from the original repo only.

Also you can keep the original remote (origin) and create an alternative remote and use it to push both repositories:

git remote add both
git remote set-url --add --push both 
git@git.company.es:group_1/project.git
git remote set-url --add --push both git@git.other.es:test/project.git

And your remote configuration will be:

git remote -v
origin  git@git.company.es:group1/project.git (fetch)
origin  git@git.company.es:group1/project.git (push)
both    git@git.company.es:group1/project.git (fetch)
both    git@git.company.es:group1/project.git (push)
both    git@git@git.other.es:test/project.git (push)

And now you can decide which remote you want to use in different situations.



来源:https://stackoverflow.com/questions/47910773/single-directory-pointing-to-multiple-git-repositories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!