GIT Practical Reference

How to .gitignore

In Git, the .gitignore file is used to specify which files and directories should be ignored by Git when tracking changes in your project.

Creating a .gitignore file

To create a .gitignore file, you can use a text editor or run the following command in your project's root directory:

touch .gitignore ```bash This command creates an empty `.gitignore` file. ### .gitignore Syntax The `.gitignore` file uses simple patterns and rules to specify which files and directories should be ignored. Here are some commonly used syntax rules: - `#` at the beginning of a line indicates a comment. - `*` matches any number of characters. - `?` matches a single character. - `/` separates directory names. - `!` negates a pattern. ### Ignore specific files To ignore specific files, simply list their names in the `.gitignore` file. For example, to ignore a file named `config.ini`, add the following line to `.gitignore`: ```bash config.ini

Ignore all files with a certain extension

To ignore all files with a specific extension, use the *.extension pattern. For example, to ignore all .log files, add the following line:

*.log

Ignore all files in a directory

To ignore all files in a specific directory, use the directory name followed by /*. For example, to ignore all files in a directory named logs, add:

logs/*

Ignore all .DS_Store files for mac

**/.DS_Store

Ignore specific files in a directory and its subdirectories

To ignore all files in a directory and its subdirectories, use the directory name followed by /**. For example, to ignore all .tmp files in the temp directory and its subdirectories:

temp/**.tmp

Negate Patterns

You can negate patterns to include files or directories that would otherwise be ignored. For example, to ignore all .log files except for important.log, you can use:

*.log
!important.log