0 votes
1 view
in DevOps and Agile by (19.8k points)

What is the proper syntax for the .gitignore file to ignore files in a directory?

Would it be




















1 Answer

+1 vote
by (63.4k points)
selected by
Best answer


  • A blank line matches no files, thus it will serve as a separator for readability.

  • A line starting with # is a comment.

  • An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern can become included again. If a negated pattern matches, this can override lower precedence patterns sources.

  • 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 alternative 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 approach how pathspec works in general in git).

  • If the pattern doesn't contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the top level of the work tree if not from a .gitignore file).

  • Otherwise, git treats the pattern as a shell glob appropriate for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards within the pattern won't match a / in the pathname. For example, Documentation/*.html matches Documentation/git.html however not Documentation/ppc/ppc.html or tools/perf/Documentation/perf.html.

  • A leading slash matches the start of the pathname. For example, /*.c matches cat-file.c but not mozilla-sha1/sha1.c.

You can find more here

git help gitignore


man gitignore

by (19.8k points)
Very well Explained!
Welcome to Intellipaat Community. Get your technical queries answered by top developers !