Git - Include and Exclude by .gitignore | Drupal 8

Git - Include and Exclude by .gitignore

Submitted by editor on Thu, 01/28/2016 - 10:25

How to Include and Exclude files using .gitignore file ?

Why gitignore not working ?

Ignore files and folders using .gitignore

Example 1. Ignore (Exclude) a simple file or a folder

Example 2. Include a file / folder

Example 2. Include a file located in a Excluded folder
Step 1. Include the 'Excluded' folder
Step 2. Exclude All files and folders in this folder
Step 3. Re Include the specific file or folder

Git Cache : gitignore not working

If files are already cached, .gitignore may not working

CAUTION !!! Do not forget to commit your changes before all this operations

1. Rebuild all cache

git rm -r --cached .
git add .
git commit -m "clear all cache to fix file tracking"

2. Remove cache of a folder already added to the git

git rm -r --cached thefile.txt thefolder

3 Remove cache of a file already added to the git

 git rm --cached sites/default/settings.php


The file .gitignore is versioned by git. If you don't want to version ignored files list, you can also "EXCLUDE" file which is located on .git/info/exclude .

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.