I had a directory named sites added to my git repository. As it contained a bootstrap file having names of each new domain in multiple sites setup hosted in the single CakePHP application it contained different domain entries and folders as compared to my application in my local machine. For the reason, I felt a need of removing it from git repository, once I had done with testing, but keeping it at both place, i.e. local machine and remote server.
How to remove remove remote directory
To do this I added the following line to my .gitignore file:
/sites
I thought it was it. I was wrong. Although it was already added to repository every time I pushed changes from my local machine the bootstrap.php file in sites directory of remote server was overwritten.
I had skipped the task of removing sites directory from repository. The following lines would have done it. Actually I required to perform this task right after adding that line to .gitignore. Here are the line removing sites directory from repository and committing changes to remote server to fix everything with this ignore.
$ git rm -r --cached sites $ git commit -m 'Remove the ignored sites directory' $ git push origin master
Next, what I want to allow a particular directory from this path? That is to record changes only to specific directory ignoring everything as usual. The line /site in .gitignore will become:
/sites/* !/sites/*/ !/sites/example.com/ !/sites/example.com/*/ !/sites/example.com/*/*/ !/sites/example.com/*/*/*/