What is .gitignore
.gitignore
is a file that Git uses to determine which files and directories to ignore, and not track, when performing operations. This is particularly useful for excluding files with sensitive data, log files, binary files, or dependency caches that do not need to be versioned and included in the Git repository.
Here’s how to use it:
Creating a .gitignore
file
You can create a .gitignore
file in the root directory of your repository. This file does not have an extension and the name should be written exactly as .gitignore
.
|
|
Editing the .gitignore
file
While you can edit it by a text editor, but a command line will make it easier. Using echo
command to append anything to the .gitignore
file. For example:
|
|
This will ignore the entire repository named RepositoryName
.
Another example:
|
|
This will ignore the the file named filename.doc
.
If you want to ignore the file with a specific suffix, then using this command:
|
|
Notes
Comments can be included in the .gitignore
file by starting a line with #
.
You can negate a pattern by starting a line with !
. This can be used to make Git ignore all files of a certain type, except for a few specific ones.