Skip to content

Using gitignore to Exclude Specific Files

There are certain files that we do not want to include in Git version control, and we also do not want them to constantly appear in the untracked list, such as node_modules, some development dependencies, compilation logs, and so on.

In such cases, we can create a .gitignore file to list the items that need to be ignored.


  • Empty lines or lines starting with the comment symbol # will be ignored.
  • Standard glob pattern matching is used.
  • If a matching pattern ends with a forward slash (/), it indicates that directories should be ignored.
  • To exclude files and directories except for specific patterns, you can prefix the pattern with ! to negate it.


# This line is a comment and will be ignored by Git

# Ignore all files with the .a extension

# Do not ignore lib.a

# Ignore the TODO file in the root directory

# Ignore the build folder

# Ignore all txt files under the doc directory (excluding subdirectories)

# Ignore all txt files under the doc directory (including all subdirectories)

References and Acknowledgments

This post is translated using ChatGPT, please feedback if any omissions.