8

Bare with the following, as I tried to think of a simple example and a common web structure came to mind. If the structure is like this:

/www
   |-- scripts
       |-- js
           `shared_code.js
       `-- css
           `shared_style.css
   |-- images
   `-- cgi-bin/
       |-- projectA
           |-- .git
           |-- foo.php
           `-- foo.pl
       `-- projectB
           |-- .git
           |-- bar.php
           `-- bar.pl

Is it possible to add the js/css scripts to the git repositories?

vol7ron
  • 40,809
  • 21
  • 119
  • 172
  • No. The `.git` directory must be at the top level of your project directories (in this case `www`). Recommend you create a `.git` under `scripts` and then turn the `www` directory into the main repo for the three [submodules](http://book.git-scm.com/5_submodules.html). –  Apr 05 '12 at 19:57
  • Trying to avoid that. I think you can do it using symbolic links, but I want to avoid that as well. – vol7ron Apr 05 '12 at 19:59
  • 1
    According to an answer in [this post](http://stackoverflow.com/questions/86402/how-can-i-get-git-to-follow-symlinks), git doesn't allow for following symlinks since version 1.6.1. –  Apr 05 '12 at 20:01
  • @Michael: thanks... even my back-up is faulty :) – vol7ron Apr 05 '12 at 20:04

1 Answers1

3

It's not possible to do what you're asking (and it's quite inadvisable anyway). However, you might look into submodules. Your projectA and projectB would contain a submodule called scripts. Of course that means you'll have to make scripts into its own repository, but that's probably a good thing. You can read up on submodules here:

https://git-scm.com/book/en/v2/Git-Tools-Submodules

LangeHaare
  • 2,776
  • 2
  • 17
  • 25
Ethan Brown
  • 26,892
  • 4
  • 80
  • 92