git-ignore:tldr:cb86b
The git ignore
command is used in Git version control to specify files and directories that should be ignored or excluded from tracking by Git.
When you add a file/directory to the Git repository, it starts tracking changes made to that file/directory. However, there are cases when you want Git to ignore certain files or directories, such as build artifacts, temporary files, or sensitive information like passwords. This is where the git ignore
command comes into play.
To use git ignore
, you need to create a file named .gitignore
in the root directory of your Git repository. Inside this file, you can specify file patterns or directory names that Git should ignore.
For example, if you want to ignore all files with the extension .log
, you can add the following line to your .gitignore
file:
*.log
You can also specify entire directories to be ignored. For instance, if you want to ignore a directory named temp
, you can add the following line:
temp/
After adding patterns to the .gitignore
file, Git will no longer track changes to the specified files or directories. However, note that if you have already committed files that match the patterns in your .gitignore
file, they will not be automatically removed from the repository. To untrack them, you need to remove them from the Git repository using the git rm
or git rm --cached
command.
Overall, the git ignore
command and the .gitignore
file give you control over what files and directories should be excluded from Git tracking and can help maintain a cleaner version control history.