![]() |
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?.gitattributes is a configuration file in the Git repository. It is used for defining paths and files in a Git repository. It defines “How git should treat certain files. This includes settings such as line endings. file encoding and merge strategies. Syntax: The syntax for .gitattributes is simple and follows a key-value format, where each line represents a path or pattern followed by its corresponding attributes. pattern attribute=value
Once you’ve defined the desired attributes in the “.gitattributes” file, save the changes and commit them to your repository like any other file. Features of .gitattributes:
Example: *.txt text=auto 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
Example: This “secrets.txt” file never commit in git repository //.gitignore file Output:
|
Feature |
‘.gitattributes’ |
‘.gitignore’ |
---|---|---|
Purpose |
Define attributes for files and paths in the repository |
It specifies files and patterns git should ignore |
Syntax |
It uses a key-value syntax to define attributes |
It uses to patterns to match file or directories to ignore |
Examples |
Set merges strategies, control line ending, specify encoding |
Exclude build artifacts, temporary files log files, etc. |
Git Operations |
Affects how Git handles tracked files during merges and operations |
This file instruct git to ignore specified files during operations. |
Both files serves different purposes in Git. They are complementary in managing your Git repository effectively. ‘.gitattributes’ helps in defining attributes for paths, while ‘.gitignore’ helps in specifying which files and directory should be ignored while working with git. Together, they contribute to maintaining a clean and organized verison-contolled project.
Reffered: https://www.geeksforgeeks.org
Git |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |