1

How do I create separate Git repositories for web applications that live in shared directories so I can deploy each to production via GitHub? The web application setups are common convention, so I'm surprised if there is not a way to accomplish this.

For each application, the index file and assets live in their respective public_html directory:

/home/user/public_html/app1
/home/user/public_html/app2
/home/user/public_html/app3

The application files for each website live in their respective upper level directory:

/home/user/app1
/home/user/app2
/home/user/app3

So where to run git init to have a repo for each application? Here are the challenges:

  1. git init in the "user" directory will create a single repo for all the applications
  2. git init in "/home/user/public_html/app1" will not include application files in "/home/user/app1"
  3. git init in "/home/user/app1" will not include index and assets in "/home/user/public_html/app1"

NOTE: This question was massively edited to use non-IIS terminology in hopes of better conveying the question.

Anshul Goyal
  • 61,070
  • 31
  • 133
  • 163
suncoastkid
  • 2,071
  • 6
  • 21
  • 44

3 Answers3

1

I think there are 3 ways to do this.

The first will be to use git submodule. Basically, you create a master repo in your directory /home/user, which happens to hae all the other repositories etc as submodules. In this case, you will need 2 repositories per app, one for app_n, another for public_html/app_n. Check sample instructions below with 2 apps:

#Create the repositories etc
cd test && mkdir repositories && cd repositories
mkdir app1 app2 public_html_app1 public_html_app2
cd app1/ && git init && touch file && git add . && git commit -m "msg" && cd ..
cd app2/ && git init && touch file && git add . && git commit -m "msg" && cd ..
cd public_html_app1/ && git init && touch file && git add . && git commit -m "msg" && cd ..
cd public_html_app2/ && git init && touch file && git add . && git commit -m "msg" && cd ..

#Create the master repo and add submodules
cd .. && mkdir deployment && cd deployment
git init && mkdir public_html
git submodule add ../repositories/app1 app1
git submodule add ../repositories/app2 app2
git submodule add ../repositories/public_html_app1 public_html/app1
git submodule add ../repositories/public_html_app2 public_html/app2
git commit -m "creating repo structure"

In the above, the deployment directory is analogous to your /home/user/ directory.

A second way to do this will be to create the public_html directory within your app_n directory, and serve the static assets etc from there itself. This should be easily configurable with apache or whichever web server you are running.

The third approach will be to use symlinks. Since you are on IIS, they will not work for you (you will need to explore virtual directories on Windows). Essentially, you can create symlinks within your public_html directories. Your public_html files will be tracked with the app only, however, you can create symlinks within the public_html directory. Check steps below to reproduce the same for 2 app scenario

mkdir -p app1/public_html app2/public_html public_html
ln -sf app1/public_html/ public_html/app1
ln -sf app2/public_html/ public_html/app2
Anshul Goyal
  • 61,070
  • 31
  • 133
  • 163
  • There is no need to maintain a separate submodule to split up a git repo. See http://stackoverflow.com/a/13738951/4231110 – Justin Howard Nov 24 '14 at 15:34
  • @justinhoward I don't think that applies here. We can maintain a single repo, but OP clearly asks in the question, `How do I create separate Git repositories for web applications...` – Anshul Goyal Nov 25 '14 at 03:19
  • The second options sounds promising. Is there an .htaccess example or a resource you know of that you could show how to accomplish serving static files from above the web root? – suncoastkid Jan 14 '15 at 13:27
  • @suncoastkid hmm no, don;t know of any resources. Anyway, if that heloed, dont forget to accept :) – Anshul Goyal Jan 14 '15 at 13:35
0

I suggest creating a git repository for each app at the /home/user/app1 level. Then create an assets directory in each one. You can then symlink /home/user/public_html/app1 to /home/user/app1/assets.

+---home
    +---user
        +---app1 (git repo)
        |   +---assets
        +---app2 (git repo)
        |   +---assets
        +---public_html
            +---app1 -> /home/user/app1/assets
            +---app2 -> /home/user/app2/assets

The git repository will include both your application and asset files, but the web server will still be able to access the asset files.

Alternatively, you could reconfigure your web server to access the assets directories directly.

Justin Howard
  • 5,057
  • 1
  • 19
  • 44
-1

So the idea from the mapping that i'm getting is that it's something like this:
Some fodlder
|
-> wwwroot
    |
    ->index
      assets
|
->inetpub

so wwwroot and inetpub are in the same main folder
if this is the case then you need to start your git init in your main folder(labeled above as "some folder"), if there are other files and folders in your "main folder" then you have to add files to your commit manually, in this case with 'git add wwwroot/assets/somepicture.png'(withought the '' offcourse) if you choose to do git add --all in this suggested case, you would add all of the files in your main folder to your commit, so that wouldn't be the best of practices.