GIT IGNORE
Understanding .gitignore
.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
?
.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 entirebuild
directory.secret.txt
: Ignore a specific file namedsecret.txt
.*.exe
: Ignore all executable files.!important.txt
: Trackimportant.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
.gitignore
FileTo create a .gitignore
file:
Navigate to your project directory in the terminal.
Use a text editor or command-line tools to create a new file named
.gitignore
.Add patterns for files or directories you want Git to ignore.
Save the
.gitignore
file.
Last updated