• Home
  • LinuxGit
  • Excluding a directory anywhere in the source tree from git

Excluding a directory anywhere in the source tree from git

Just add the following line to your .gitignore file (the file should be located in the root of the git repo):

include/

Excludes all directories named include. Suppose I’m in /home/droidzone/kernel and there are subdirectories like the following:

/home/droidzone/kernel/include
/home/droidzone/kernel/arch/arm/include
/home/droidzone/kernel/exynos/include

The above rule will stop git from tracking all these directories.

In most cases the directory had already been tracked by the time you added the gitignore rule. In such an instance you can remove all these tracked directories from the git with the following:

git rm --cached -r include/

To be effective it should be combined with a .gitignore rule.