0

We are trying to have two git repos in one root directory (to handle modules inside ie. subdirectories).

We cant use git subtree, mainly because there are files in separate subdirectories that need to be in different folders.

We decided to create 2 repos and in the .git/info/exclude file, list the subfolders we wanted ignored for one repo and vice versa. We tried to use the following exclude file for the one that only needs a few folders followed:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
*
!assets/apps/contratos/*
!api/controllers/contrato/*
!api/models/contrato/*
!api/services/contrato/*

As it is it basically ends up tracking no files, if we remove the * from the file, all files are added again.

We would like git to ignore all folders BUT the ones listed above.

NOTE: Due to our double git structure .gitignore is out of the picture -unless somebody helps with a way to create two .gitignore in the same root directory for 2 different repos.

galgo
  • 734
  • 3
  • 17
  • 45
  • 1
    This will be a mess. Instead, have one repository for the combined usage and use `git-subtree` to link in the two separate repositories. Use a build system and/or symlinks to combine them as needed. I'd suggest you instead ask a question about your situation and how to solve it. – Schwern May 23 '16 at 23:26
  • @Schwern what do you mean with a "build system"? We are doing it this way to not slow down development by creating custom code for versioning/modules. Its a patch solution, we're trying to figure out if its worth doing it – galgo May 23 '16 at 23:29
  • [A build system](https://en.wikipedia.org/wiki/Build_automation) is something that you run to compile or otherwise make the code ready to run. It also automates other tasks like testing, deployment, and style checks. Most projects eventually need one. `make`, `rake` and `ant` are a few examples. In your case it would move files from the two sub-repositories to their appropriate places. Rather asking about the attempted solution, if you showed us what your setup is that drove you to attempt this solution we could better help. – Schwern May 23 '16 at 23:31
  • Its a good approach. We are using Nodejs for a web application, so the idea was, a simple push/pull would update the project in development, but I guess we could use a simple batch to put files into places until we can develop the code for a more integrated version. Still intrigued by the exclude file issue though – galgo May 23 '16 at 23:39
  • Git is not a deployment system. If you try to cut corners and use it as one... well, you're discovering what happens. There's more to deployment than copying files. You're gonna need a build system. The more you avoid it, the more convoluted things will become. I would suggest looking into a real build system that can handle dependent actions (like building before testing or deploying) rather than rolling your own. – Schwern May 24 '16 at 00:05
  • If you have two repos in one directory, how do you know which one you're working with? – Schwern May 24 '16 at 00:06
  • By doing this: http://stackoverflow.com/questions/436125/two-git-repositories-in-one-directory And its not for deployment but for development purposes only. – galgo May 24 '16 at 00:07
  • 1
    I second @Schwern's answer. This will be a mess and very hard to maintain. I can feel the pain of the poor dev who takes this project once you move on to a new project or company. There are better ways to share code between projects, including creating your own npm packages that you can depend from... – C. Augusto Proiete May 24 '16 at 05:01

1 Answers1

1

I think what you are after is

/*
!/assets/
/assets/*
!/assets/apps/
/assets/apps/*
!/assets/apps/contratos/
!/api/
/api/*
!/api/controllers/
/api/controllers/*
!/api/controllers/contrato/
!/api/models/
/api/models/*
!/api/models/contrato/
!/api/services/
/api/services/*
!/api/services/contrato/
Vampire
  • 35,631
  • 4
  • 76
  • 102