Git: Is it possible to add files located in an external directory to a git repository?

Go To StackoverFlow.com

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?

2012-04-05 19:53
by vol7ron
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 - NoName 2012-04-05 19:57
Trying to avoid that. I think you can do it using symbolic links, but I want to avoid that as well - vol7ron 2012-04-05 19:59
According to an answer in this post, git doesn't allow for following symlinks since version 1.6.1 - NoName 2012-04-05 20:01
@Michael: thanks... even my back-up is faulty : - vol7ron 2012-04-05 20:04


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

2012-04-05 20:15
by Ethan Brown
Ads