Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Git - Include and Exclude by .gitignore

By editor , 28 January, 2016
Question

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
sites/default/settings.php
sites/*/files

Example 2. Include a file / folder
!sites/default/testfile.php
!sites/*/testfolder

Example 2. Include a file located in a Excluded folder
Step 1. Include the 'Excluded' folder
!sites/*/files
Step 2. Exclude All files and folders in this folder
sites/*/files/*
Step 3. Re Include the specific file or folder
!sites/default/files/my_included_file.pdf

Git Cache : gitignore not working

If files are already cached, .gitignore may not working

Solutions.
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

 

Note
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 .

Tags

  • Git
  • Server
  • Shell
Make Correction on a git

Comments

Plain text

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

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer