GIT IGNORE

Understanding .gitignore

The .gitignore file is a text file used to specify intentionally untracked files that Git should ignore. These files can be specific files, directories, or patterns of files.

Why Use .gitignore?

Git tracks changes to files in your project directory. However, there are certain files that you don't want Git to track, such as temporary files, build artifacts, or sensitive information like passwords. The .gitignore file allows you to specify which files Git should ignore, preventing them from being included in commits.

Syntax

Each line in a .gitignore file specifies a pattern for files or directories to ignore. Here's a breakdown of the syntax:

  • Blank Lines: Blank lines are ignored.

  • Comments: Lines beginning with # are treated as comments and ignored.

  • Patterns: Each line specifies a pattern to match files or directories. Patterns can include wildcards (* and ?) and character ranges ([abc]).

  • Negation: Prefixing a pattern with ! negates it, meaning Git will track files matching the negated pattern even if they match an earlier ignore rule.

  • Slash /: If a pattern ends with a slash /, it matches directories only, not files within the directory.

Examples

Here are some examples of patterns commonly used in .gitignore files:

  • *.log: Ignore all files with the .log extension.

  • build/: Ignore the entire build directory.

  • secret.txt: Ignore a specific file named secret.txt.

  • *.exe: Ignore all executable files.

  • !important.txt: Track important.txt even though other files with similar extensions are ignored.

Let said, if you want to ignore all the content from the vendor folder from push or pull repository, just add follwing command at your .gitignore file, which means that any files or directories within the vendor folder, along with the vendor folder itself, will be excluded from version control.

vendor/

Creating a .gitignore File

To create a .gitignore file:

  1. Navigate to your project directory in the terminal.

  2. Use a text editor or command-line tools to create a new file named .gitignore.

  3. Add patterns for files or directories you want Git to ignore.

  4. Save the .gitignore file.

Last updated