Search code examples
gitgitignore

Ignore committing a specific directory to git


I am aware that giving the path of file or directory in the .gitignore file does not add those files to my git repository, but I wanted to ignore all "build" directories created in my repository, I don't want to specify the complete path of my individual build directory every time. Please suggest the solution.


Solution

  • If all your target directories are called "build", then you can write this in gitingnore:

    [Bb]uild/
    

    This should solve the problem. From the documentation:

    If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In other words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the way how pathspec works in general in Git).