Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

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?

like image 720
vol7ron Avatar asked Apr 05 '12 19:04

vol7ron


People also ask

How to add files to a directory in Git?

It is currently blank, but you plan to add files to it that Git should track. The only solution is to create a file in the directory and add it to the Git. Git community has settled on creating an empty file called .keep in the directory and adding it to the index.

How do I create a new repository in Git?

Initiate a New Git Repository You can start using Git with any set of files on your computer. All you need to do is “initiate” a Git repository from within the directory that contains your files. All you need to is navigate to the directory in which your files reside and type the following command:

How do I move a file from one Git repo to another?

Move the /var/data/public/ directory into your Git-repo root (/var/data/my-app). Create a sym-link (symbolic link) inside of /var/data/public to the /var/data/my-app/public folder, using: ln -s source_file_or_directory virtual_file_or_directory Then, just add the moved file or directory to Git using git add in the normal fashion.

How do I exclude a file from a git repository?

Any file listed on its own line in this file will be ignored by git, even if you add a whole directory to staging. You can also use astericks as wildcards. For example, if you want to exclude a file called “notes.html” and all .txt files from your repository, you can use the following rule in the ignore file:


1 Answers

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

like image 61
Ethan Brown Avatar answered Sep 27 '22 21:09

Ethan Brown