0

I have a PHP web app I want to bundle into a Git repository on GitHub, but I’m unclear how because the user interface is in the webroot but the models, controllers, storage, and so forth are in a folder outside the webroot for security purposes. I.e. it looks like:

C:/inetpub
    |—App_code_directory
    |—Lots_of_unwanted_directories
    |—wwwroot
        |—App_interface_directory
        |—Lots_of_unwanted_directories

Can I build a repository directly from the two App directories? Do I need to base it off inetpub and just create a huge .gitignore file? This is obviously a common application architecture, but I haven’t been able to phrase my web searches in a way that will yield answers.

UPDATE: I added an answer below showing how I did it, which was a more efficient .gitignore file than I'd originally envisioned.

dspitzle
  • 740
  • 2
  • 9
  • 26

2 Answers2

2

Yes, you can build one repository from both directories, and exclude the Lots_of_unwanted_directories. In this example, you would

  1. cd c:\inetpub
  2. echo "Lots_of_unwanted_directories" > .gitignore
  3. git init .
  4. git add remote origin <your github url here>
  5. git commit . -m "Initial commit"
  6. git push origin master

But wait. Just because it's possible doesn't mean it's a good idea. You would want to move your source code into a different workspace folder first, and have a buildfile or task that publishes to c:\inetpub.

Timir
  • 1,395
  • 8
  • 16
  • Ok, it sounds like you're advising that I'd need to add the top-level directory to the repository and just add everything I'm disinterested in to .gitignore. On the other hand, I think you may have hit on another alternative: write the code in a unified directory, and publish both the web components and the code to destination folders on the development machine. If you can add a suggestion of how to do that I may give it a try. – dspitzle May 08 '18 at 20:42
  • 1
    Choose a build system that you’re familiar with. I use gradle, ant, maven, gulp, grunt depending on type of project. In case you haven’t used any of those, I’d suggest using ant because that’s the least opinionated and therefore most customizable. – Timir May 09 '18 at 03:53
  • Ok, thanks for the recommendation, I haven’t had call for a build system, so I’ll look into it. – dspitzle May 09 '18 at 10:32
0

After looking around and finding how to .gitignore everything except select elements, I decided to just create a repository off of my inetpub directory and include just the parts I need. Here's how the resulting .gitignore looks.

# Start by excluding everything
*

# Add back in all subdirectories, but not their contents
!/*

# Remove any files within the base directory
*.*

# Add the code base folder contents
!PROJECT_base/**

# Add back in the wwwroot subdirectory
!wwwroot/*

# Remove any files in the wwwroot subdirectory
wwwroot/*.*

# Add the interface folder and contents
!wwwroot/PROJECT/**

# Remove any files from the storage folders
PROJECT_base/storage/uploads/*.*
PROJECT_base/storage/downloads/*.*
wwwroot/PROJECT/downloads/*.*

# Add the stub files back
!**/stub.txt
dspitzle
  • 740
  • 2
  • 9
  • 26