0

I have code that read from Git commits, branches and etc.

In order to test it, I have created a test project with a .git folder and put it inside in project.

Now, I want to add the whole project including the test case to Git! So technically, some files in my "test project" will mapped to two git repo (the main one and the test fake one)

I am wondering if it is possible. If not, what is a workaround?

To be more clear, this is my project tree

.git
MainProject
   |main
   |test
       |Resources
           |TestProj
               |.git
               |test.txt
Afshin Moazami
  • 2,092
  • 5
  • 33
  • 55
  • you're effectively asking to add a second remote. see http://stackoverflow.com/questions/11690709/can-a-project-have-multiple-origins and http://stackoverflow.com/questions/849308/pull-push-from-multiple-remote-locations – RaGe Apr 24 '15 at 15:33
  • My test repo, doesn't have any remote. So, I guess that's not answering my question. – Afshin Moazami Apr 24 '15 at 15:44
  • 3
    Your question isn't entirely clear, but it sounds like you might want to look into [submodules](http://git-scm.com/book/en/v2/Git-Tools-Submodules) or one of their alternatives like [subtrees](http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/). – ChrisGPT was on strike Apr 24 '15 at 15:44
  • Discussing with a colleague, I found it better to zip the TestProj. And in my test cases I will unzip it every time. Using this workaround, I will assure that every time I run the test, the test repo is the same. – Afshin Moazami Apr 24 '15 at 17:00
  • @Chris Although, I would be able to solve the issue by using submodules or subtrees, I believe this is not the purpose of these features. Also, as mentioned in my previous comment, probably a zip file (or creating the repo in the test setup) would be better solution since it would be stateless – Afshin Moazami Apr 24 '15 at 17:02
  • Whoa, wait, what? You want to move the test suite to a *completely* different repository? Why? – Makoto Apr 24 '15 at 21:51
  • No, my test suit includes a test repo – Afshin Moazami Apr 26 '15 at 21:04

1 Answers1

1

There are several ways to do this:

Subtree merges

If you want to end up with a single Git repository, but preserve the history of both of your projects, then subtree merge is for you:

http://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging

Submodules

If you want to keep both projects separate, but have an relatively easy way to work with both, then submodules are the answer.

http://git-scm.com/docs/git-submodule

Subtree

If you want both projects to continue existing, but also expose a super-repository containing both, then git-subtree is for you.

http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65