What is a “.gitignore”?
A “.gitignore” file is a text file used in Git repositories to specify intentionally tracked files and directories that Git should ignore. Sometimes you don’t want to track sensitive data in your git history. They used “.gitignore” file to untracked file. This helps keep your repository clean, focused on the essential source code and resources, and avoids cluttering the version control history with irrelevant files.
Syntax:
The syntax for .gitignore is straightforward, allowing users to specify files, directories, or patterns to ignore. Anything you write in .gitignore file will be ignored by git.
Features of .gitignore
- Ignoring Build Artifacts: Exclude compiled binaries, object files, and build directories.
- Ignoring IDE Files: Ignore project files and directories specific to certain IDEs or text editors.
- Ignoring System Files: Exclude files generated by the operating system or editor.
- Ignoring Sensitive Information: Exclude files containing sensitive information like credentials or API keys.
- Custom Patterns: Define custom patterns to ignore specific types of files or directories.
Example: This “secrets.txt” file never commit in git repository
//.gitignore file
secrets.txt
Output:
.gitattributes vs .gitignore in Git
Git is a command line tool. It is a distributed version control system(DVCS) widely used for tracking changes in source code during software development. It was created by Linux Torvalds in 2005 to manage the development of the Linux Kernel. In this post, we will understand the two git files .gitattributes and .gitignore.
Table of Content
- What is .gitattributes?
- What is a “.gitignore”?
- Difference between .gitattributes and .gitignore
- Conclusion