If you are using Simulink Embedded Coder, you will find that multiple subfolders are generated in the project directory. These subfolders contain automatically generated code, such as .c and .h, but also contain many temporary files. When using Git for version control, we expect to put these automatically generated .c and .h under version control, but ignore other temporary files. In the process of writing gitignore, I found that different ways of writing gitignore will have different results.


  • ! negates the pattern, any matching file excluded by a previous pattern will become included again.
    • Put a backslash ("\") in front of the first "!" for patterns that begin with a literal "!", for example, "\!important!.txt".
  • / directory separator.
    • If there is a separator at the beginning or middle (or both) of the pattern, then the pattern is relative to the directory level of the particular .gitignore file itself. Otherwise the pattern may also match at any level below the .gitignore level.
    • If there is a separator at the end of the pattern then the pattern will only match directories, otherwise the pattern can match both files and directories.
    • For example, a pattern doc/frotz/ matches doc/frotz directory, but not a/doc/frotz directory; however frotz/ matches frotz and a/frotz that is a directory (all paths are relative from the .gitignore file).
  • * asterisk matches anything except "/".
  • ? matches any one character except "/".
  • [a-zA-Z] range notation matches one of the characters in a range.
  • ** two consecutive asterisks matches against full pathname, includes "/".

How ! works

As we all knew, an optional prefix "!" which negates the pattern. However, this only works when the parent folder of the pattern is not ignored, e.g.,

#ignore the folder slprj

#the following negate pattern will not work, because slprj/ is ignored
#ignore the contents of slprj

#negate one subfolder of slprj

#ignore the contents of subfolders in slprj/ert

#negate the following pattern (in slprj/ert/ or its subfolder)

A .gitignore example for Simulink Coder project



gitignore – Specifies intentionally untracked files to ignore

Categories: CodingComputer


Leave a Reply

Your email address will not be published.