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?
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.
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:
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.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With