### Versioned Template Workflow Example Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Demonstrates the workflow for creating a versioned template when significant changes occur between major versions. ```text Version 1.x: Laravel.gitignore (root - widely used) ↓ (version 2.0 released, patterns change significantly) Version 2.x: Laravel.gitignore (root - new version) Version 1.x: community/Laravel_1.x.gitignore (archive) ``` -------------------------------- ### Example of Gitignore Precedence Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Illustrates how repository-specific, subdirectory, and global .gitignore files interact, showing which rules take precedence. ```text Repository/.gitignore: Ignores *.log Global .gitignore: Ignores .vscode/ Subdirectory/.gitignore: Includes !.vscode/launch.json (in root .gitignore it's negated) Result: *.log ignored everywhere .vscode/ ignored globally .vscode/launch.json included per subdirectory rule ``` -------------------------------- ### Directory Pattern Example Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md A pattern to ignore an entire directory and its contents. ```gitignore build/ ``` -------------------------------- ### Select Gitignore Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Choose appropriate gitignore templates based on your project's technology stack, including single and multiple technology examples. ```text Node.js + Express.js project → Use: Node.gitignore ``` ```text Full-stack project: React frontend + Python backend → Use: Node.gitignore (for frontend build) → Use: Python.gitignore (for backend) ``` ```text Any project on macOS using VS Code → Use: [Primary template] → Add: Global/VisualStudioCode.gitignore → Add: Global/macOS.gitignore ``` -------------------------------- ### React/Vue/Angular Project Setup Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For React, Vue, or Angular projects using npm, Node.gitignore is recommended to cover npm and build artifacts. Include Global/VisualStudioCode.gitignore if using VS Code and OS-specific files. ```text Technology: React/Vue/Angular with npm ↓ Use: Node.gitignore (covers npm, node_modules, build) Global/VisualStudioCode.gitignore (if using VS Code) OS: + Global/macOS.gitignore or Global/Windows.gitignore ``` -------------------------------- ### Update a .gitignore Template Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md This example demonstrates how to download the latest version of a specific .gitignore template, compare it with your current .gitignore file, and replace it if the changes are desirable. Finally, it shows how to commit the update. ```bash # Download latest version of a template curl https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore > Python-latest.gitignore # Review differences diff .gitignore Python-latest.gitignore # If updates look good, replace cp Python-latest.gitignore .gitignore # Commit the update git add .gitignore git commit -m "Update Python.gitignore template to latest version" ``` -------------------------------- ### Research Node.js Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Use npm commands to install, build, and test a Node.js project. Then, use 'git status --ignored' to identify newly generated ignored files. ```bash # Example: Researching Node.js patterns npm install package npm run build npm test # What new files/directories appeared? git status --ignored ``` -------------------------------- ### Include Official Documentation Link in .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Add URLs to official documentation for patterns to help users understand why they are recommended. This example shows how to link to Sphinx documentation. ```gitignore # Sphinx documentation # https://www.sphinx-doc.org/ docs/_build/ ``` -------------------------------- ### InforCRM .gitignore Template Source: https://github.com/github/gitignore/blob/main/README.md Example of a specialized .gitignore template for InforCRM, including rules for generated files and deployment configurations. It also shows how to force include specific directories. ```gitignore # gitignore template for InforCRM (formerly SalesLogix) # website: https://www.infor.com/product-summary/cx/infor-crm/ # # Recommended: VisualStudio.gitignore # Ignore model files that are auto-generated ModelIndex.xml ExportedFiles.xml # Ignore deployment files [Mm]odel/[Dd]eployment # Force include portal SupportFiles !Model/Portal/*/SupportFiles/[Bb]in/ !Model/Portal/PortalTemplates/*/SupportFiles/[Bb]in ``` -------------------------------- ### Simple Glob Pattern Example Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md A basic glob pattern to ignore all files with a specific extension. ```gitignore *.log ``` -------------------------------- ### Character Class Pattern Example Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md A pattern using character classes to match variations in directory names. ```gitignore dist[0-9]/ ``` -------------------------------- ### Versioned Code with Multiple Frameworks .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For projects supporting multiple framework versions, use community templates for older versions and the root template for the current version. For example, use community/DotNet/ for .NET Framework and Dotnet.gitignore for .NET Core. ```bash # For projects supporting multiple versions of a framework: Use: community/ templates for previous versions Root template for current version Example: community/DotNet/ for .NET Framework Dotnet.gitignore for .NET Core ``` -------------------------------- ### Negation Pattern Example Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md A negation pattern used to explicitly un-ignore a specific file that would otherwise be ignored. ```gitignore !.gitkeep ``` -------------------------------- ### Double Wildcard Pattern Example Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md A double wildcard pattern to ignore files recursively within any directory structure. ```gitignore **/*.pyc ``` -------------------------------- ### Improving Pattern Organization Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Provides an example of reorganizing .gitignore patterns by category for better readability and maintainability. Shows a scattered organization versus a categorized one. ```gitignore # OLD: Scattered organization build/ *.log .env node_modules/ coverage/ .vscode/ # NEW: Organized by category # Logs *.log # Dependencies node_modules/ # Build build/ coverage/ # Environment .env # IDE .vscode/ ``` -------------------------------- ### React Native Application .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For React Native projects, start with Node.gitignore for the JavaScript/npm base. If native Android code is present, also include Android.gitignore. ```text Technology: React Native ↓ Use: Node.gitignore (JavaScript/npm base) Android.gitignore (if native Android code) ``` -------------------------------- ### Gitignore Pattern Precedence Example Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Demonstrates how Git evaluates patterns in order, with the last matching pattern determining the ignore status. Negation patterns ('!') can override previous rules. ```gitignore # Example: Complex precedence *.txt # Ignore all .txt files (step 1) !important.txt # Don't ignore important.txt (step 2) *.log # (doesn't affect .txt files) ``` -------------------------------- ### Order of Patterns Matters Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Patterns are evaluated sequentially. A file must be unignored before it can be ignored again. This example shows a working negation. ```gitignore # This works (important.log is unignored) *.log !important.log ``` -------------------------------- ### Example of Avoiding Duplicates in .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md This snippet illustrates how to handle common patterns that appear in multiple .gitignore templates. It shows keeping a single instance of a pattern and adding a comment to indicate its relevance across different template sources. ```gitignore # Python and Node templates both ignore: .env # Both have this # Solution: Keep only one instance, add comment .env # Environment variables (Python, Node) ``` -------------------------------- ### Fixing Over-Matching Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Shows how to correct .gitignore patterns that are too broad. The example contrasts a pattern that matches both files and directories with a more specific pattern that only matches directories. ```gitignore # PROBLEM: Matches too much build # Ignores "build" file AND "build" directory # FIX: Specific to directories build/ # Only ignore directories ``` -------------------------------- ### Full-Stack Web Application .gitignore Strategy Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For full-stack applications, combine .gitignore templates relevant to each part of the stack. For example, use Node.gitignore for frontend build tools and Python.gitignore for Python backends. ```text Technology: Next.js frontend + Node.js backend ↓ Use: Node.gitignore (covers entire stack) ``` ```text Technology: React frontend + Python/Django backend ↓ Use: Node.gitignore (frontend build tools) Python.gitignore (Python dependencies) ``` ```text Technology: Next.js frontend + Go backend ↓ Use: Node.gitignore (frontend) Go.gitignore (backend) ``` -------------------------------- ### Update Outdated .gitignore Documentation Links Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Ensure links in .gitignore templates point to current documentation. This example shows how to replace a broken or outdated link with a current one. ```comment # Problem: Link to old docs (archived/moved) # https://old-docs.example.com (link broken) # Solution: Update to current documentation # https://docs.example.com ``` -------------------------------- ### Order of Patterns Matters (Incorrect) Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md This example demonstrates an incorrect negation order where a file remains ignored because the negation pattern appears after the general ignore pattern. ```gitignore # This doesn't work (important.log stays ignored) !important.log *.log ``` -------------------------------- ### Fix .gitignore Under-Matching Pattern Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md If a .gitignore pattern does not match all desired artifacts, expand the pattern to cover variations or document the limitation. This example addresses a pattern that only ignores '.log' files but misses recent log variations. ```gitignore # Problem: Only ignores .log, misses recent log variations *.log # Misses: .log.1, .log.gz, .log.2024-06-24 # Better: Cover variations *.log* ``` -------------------------------- ### Resolve Conflicting .gitignore Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md When two templates have conflicting rules, document the dependency or consolidate patterns. This example illustrates a conflict where one template ignores the 'build/' directory, while another includes a subdirectory within it. ```gitignore # Template A: Ignore everything in build/ build/ # Template B: Include build/dist/ !build/dist/ # Conflict when both used together ``` -------------------------------- ### Fix .gitignore Over-Matching Pattern Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md When a .gitignore pattern ignores more than intended, make the pattern more specific or use negation for exceptions. This example shows how to refine a pattern that ignores all directories starting with 'test'. ```gitignore # Problem: Ignores all directories starting with "test" test/ # Also ignores: tests/, testing/, test_data/, etc. # Better: More specific test/ # If only this exact directory exists ``` -------------------------------- ### Test .gitignore Template Locally Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Set up a test repository, copy the new .gitignore, create files that the tool generates, and use 'git check-ignore -v *' and 'git status --ignored' to verify patterns. ```bash # Create test environment mkdir test_repo && cd test_repo && git init cp ../new.gitignore .gitignore # Create files the tool generates # (use actual tool if possible) mkdir build touch build/artifact.o touch *.log # Check what's ignored git check-ignore -v * git status --ignored # Verify expected files are ignored # Verify important files are NOT ignored ``` -------------------------------- ### Wildcard Pattern Example Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md Wildcard patterns used to ignore files matching specific extensions, often language-specific. ```gitignore *.o *.so ``` -------------------------------- ### Set Up Global Gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Configure a personal global gitignore file to apply to all repositories on your system. This involves creating the file and telling Git where to find it. ```bash # Create global gitignore file touch ~/.gitignore_global # Configure Git to use it git config --global core.excludesfile ~/.gitignore_global ``` -------------------------------- ### Specific Directory Ignore Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Illustrates how to correctly ignore directories versus files, and how to specify ignore rules at the root versus subdirectories for better specificity. ```gitignore build # Ignores anything named "build" anywhere # Better: build/ # Only ignores directories named build /build/ # Only ignores build at root ``` -------------------------------- ### Docker and Kubernetes .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For Docker containerization, use Global/Docker.gitignore if available, or create custom patterns. For Kubernetes manifests, custom patterns are typically needed, though community templates might assist. ```text Technology: Docker containerization ↓ Use: Global/Docker.gitignore (if such template exists) OR create custom patterns for Docker artifacts ``` ```text Technology: Kubernetes manifests ↓ Use: Custom patterns (templates in community may help) ``` -------------------------------- ### Comments in Gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Lines starting with '#' are treated as comments and ignored by Git. Use '\#' to match a literal hash character. ```gitignore # This is a comment # Ignore all Python compiled files *.pyc ``` ```gitignore # Ignore files starting with hash \#filename ``` -------------------------------- ### Frontend Only Web Development Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For static HTML/CSS/JavaScript projects, use Node.gitignore if npm or build tools are involved, otherwise use Global/VisualStudioCode.gitignore. Always consider OS-specific gitignore files. ```text Technology: Static HTML/CSS/JavaScript ↓ Use: Node.gitignore (if using npm/build tools) OR Global/VisualStudioCode.gitignore (if manual) OS: + Global/macOS.gitignore or Global/Windows.gitignore ``` -------------------------------- ### Selecting a Single Technology Template Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md Choose the root-level template that matches your primary language or framework for single-technology projects. ```text Project: Python web app using Django Selection: Python.gitignore ``` -------------------------------- ### Go Backend Development .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Go.gitignore for Go microservices and projects involving protobuf (gRPC). ```text Technology: Go microservice ↓ Use: Go.gitignore ``` ```text Technology: Go + protobuf (gRPC) ↓ Use: Go.gitignore ``` -------------------------------- ### Selecting Version-Specific Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md Use community directory templates for version-specific needs, especially for legacy projects. ```text Project: Legacy .NET Framework project Selection: community/DotNet/[appropriate version] ``` -------------------------------- ### Adding Support for New Tool Version Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Illustrates how to update a .gitignore template to include new artifact types introduced in a newer version of a tool. Shows old patterns and new patterns with comments explaining the additions. ```gitignore # OLD: For tool version 1.x build/ # NEW: For tool version 2.x build/ dist/ # Version 2.x introduced dist output .output/ # New in version 2.0 ``` -------------------------------- ### Monorepo .gitignore Strategy Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For monorepos, either create a main .gitignore combining rules from all technologies or use directory-specific .gitignore files for each sub-project. ```bash # Create main .gitignore combining all relevant templates # or use directory-specific .gitignore files: root/ .gitignore # Common patterns frontend/ .gitignore # Node.gitignore patterns package.json backend/ .gitignore # Python.gitignore patterns requirements.txt ``` -------------------------------- ### Build Systems Gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md General gitignore patterns for common build systems like Gradle, Maven, and CMake. ```gitignore # Gradle .gradle/ build/ *.class # Maven target/ *.jar *.war # CMake CMakeFiles/ cmake_install.cmake Makefile ``` -------------------------------- ### Adding Patterns for New Framework Features Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Demonstrates updating a .gitignore template to include patterns for modern framework features, such as build caches for Next.js and Nuxt.js. Compares basic Node.js patterns with more comprehensive ones. ```gitignore # OLD: Basic Node.js node_modules/ npm-debug.log # NEW: Including modern framework patterns node_modules/ npm-debug.log .next/ # Next.js build cache .nuxt/ # Nuxt build cache dist/ # General distribution ``` -------------------------------- ### Ignore Local Environment Configuration Files Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Ignores local environment files (e.g., .env, .env.local) to prevent sensitive configuration details from being committed, while keeping example configuration files tracked. ```gitignore # Environment files (most language templates include these) .env .env.local .env.*.local # Configuration templates (kept for reference) !.env.example ``` -------------------------------- ### Identify Project Technologies Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Determine the primary language, framework, and tools for your project to select the correct gitignore templates. ```text Python web application using Django and PostgreSQL → Primary: Python → Framework: Django (covered by Python.gitignore) → Database: PostgreSQL (not in root templates, use general ignore) ``` -------------------------------- ### Consistent Pattern Usage Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Highlights the principle of consistency, showing how similar concepts like dependency directories or build outputs should use similar patterns across different project types (e.g., Python, Node, Java). ```gitignore # All Python/Node/Java use similar patterns for: # - Dependency directories # - Build outputs # - IDE metadata ``` -------------------------------- ### Track Specific VS Code Configuration Files Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Configure .gitignore to ignore most of the .vscode directory but specifically track user settings and launch configurations. ```gitignore # Ignore most of .vscode (from Global/VisualStudioCode.gitignore) .vscode/* # But DO track settings and launch configurations !.vscode/settings.json !.vscode/launch.json ``` -------------------------------- ### Java Backend Development .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For Spring Boot applications, use Java.gitignore and Gradle.gitignore if applicable. For Maven-based applications, use Java.gitignore and Maven.gitignore. ```text Technology: Spring Boot application ↓ Use: Java.gitignore Gradle.gitignore (if using Gradle) ``` ```text Technology: Maven-based application ↓ Use: Java.gitignore Maven.gitignore ``` -------------------------------- ### Selecting Multiple Technology Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md Combine root-level templates with complementary ones for projects involving multiple technologies. ```text Project: Node.js + Python backend Selection: Node.gitignore + Python.gitignore ``` -------------------------------- ### Selecting Specialized Framework Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md Utilize community templates for less mainstream technologies or specialized frameworks. ```text Project: Tauri desktop application Selection: community/Tauri.gitignore ``` -------------------------------- ### GitBook Documentation .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use GitBook.gitignore for projects using GitBook for documentation. ```text Technology: GitBook documentation ↓ Use: GitBook.gitignore ``` -------------------------------- ### Jekyll Documentation .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Jekyll.gitignore for Jekyll-based static site blogs. ```text Technology: Jekyll-based blog ↓ Use: Jekyll.gitignore ``` -------------------------------- ### Gitignore Conditional Recommendations Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Provide guidance on when specific patterns should be applied, such as ignoring pyenv version files for libraries. ```gitignore # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: # .python-version ``` -------------------------------- ### Subdirectory .gitignore Precedence Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Demonstrates how rules in a root .gitignore and a subdirectory .gitignore can interact, using negation to include specific directories that would otherwise be ignored. ```gitignore # Root .gitignore build/ # Ignore all build directories # subdir/.gitignore !build/output/ # But include this one ``` -------------------------------- ### Gitignore Negation and Exceptions Source: https://github.com/github/gitignore/blob/main/_autodocs/project-overview.md Illustrates how to ignore an entire directory while excluding a specific subdirectory using negation patterns. ```gitignore # Ignore entire directory node_modules/ # But not this subdirectory !node_modules/.bin/ ``` -------------------------------- ### Clear and Readable Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Demonstrates the principle of clarity by preferring simple, readable patterns over complex or clever ones. Use comments to explain the purpose of patterns. ```gitignore # Good: Clear and simple build/ # Avoid: Unnecessarily complex [Bb]uild/ # When simple lowercase works ``` -------------------------------- ### Basic .gitignore Template Structure Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md A standard .gitignore template structure including sections for logs, dependencies, build outputs, testing artifacts, IDE configurations, and operating system files. ```gitignore # Technology Name # Brief description of what is ignored # Logs logs *.log # Dependencies node_modules/ # Build dist/ build/ # Testing coverage/ .nyc_output/ # IDE .vscode/ .idea/ # OS .DS_Store ``` -------------------------------- ### Basic Gitignore Template Structure Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md A standard .gitignore template includes a header with the template name and a brief description, followed by logically grouped sections of patterns. Comments are used extensively to explain patterns and reference external documentation. ```gitignore # Template Name # Brief description of what is ignored # Section 1: Common Artifacts pattern1 pattern2 # Section 2: Generated Files # Reference: https://tool-documentation.com pattern3 pattern4 ``` -------------------------------- ### Selecting Editor/OS Specific Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/template-catalog.md Add Global templates for your development environment, such as editors and operating systems, to your primary template selection. ```text Project: Any project, using VS Code on macOS Selection: [Primary template] + Global/VisualStudioCode.gitignore + Global/macOS.gitignore ``` -------------------------------- ### Include File in Ignored Directory (Correct) Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md To include a file within an ignored directory, unignore the directory first, then specify the file. ```gitignore # Correct approach build/ !build/ !build/output.txt ``` -------------------------------- ### Cross-Reference Gitignore Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/project-overview.md Use comments to indicate recommended related gitignore templates for comprehensive project coverage. ```gitignore # Recommended: VisualStudio.gitignore # Recommended: Node.gitignore ``` -------------------------------- ### Integrate Gitignore Templates via Git Clone Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Clone the gitignore repository and manually copy/append template contents to your project's .gitignore file. ```bash git clone https://github.com/github/gitignore.git cp gitignore/Python.gitignore . cp gitignore/Global/VisualStudioCode.gitignore .gitignore_vscode # Merge into .gitignore cat .gitignore_vscode >> .gitignore ``` -------------------------------- ### Include File in Ignored Directory (Incorrect) Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Attempting to include a file in an ignored directory without first unignoring the directory will fail. ```gitignore # To include a file in an ignored directory, must unignore the directory first build/ !build/output.txt # Won't work - directory is still ignored ``` -------------------------------- ### Native Android Development .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Android.gitignore for native Android development using Kotlin or Java. ```text Technology: Native Android (Kotlin/Java) ↓ Use: Android.gitignore ``` -------------------------------- ### Simple vs. Complex Gitignore Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Compares the performance implications of simple glob patterns versus more complex ones. ```gitignore # Fast: Simple glob *.log # Slower: Complex pattern [a-z]+\.[a-z0-9]*\.log ``` -------------------------------- ### Repository Structure Overview Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Provides a high-level view of the gitignore project's directory layout. ```tree github/gitignore/ ├── README.md # Project overview ├── CONTRIBUTING.md # Contribution guidelines ├── LICENSE # CC0-1.0 license ├── .github/ │ ├── PULL_REQUEST_TEMPLATE.md # PR template │ └── workflows/ # CI/CD workflows ├── [ROOT_TEMPLATES] # ~160 templates ├── Global/ # ~50 global templates ├── community/ # ~40+ specialized templates │ ├── AWS/ │ ├── DotNet/ │ └── ... └── [configuration files] ``` -------------------------------- ### WordPress/CMS Project .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For WordPress plugin/theme development, use WordPress.gitignore. For custom Drupal modules, use Drupal.gitignore and potentially PHP.gitignore. Include OS and IDE-specific gitignores. ```text Technology: WordPress plugin/theme development ↓ Use: WordPress.gitignore OS: + Global/VisualStudioCode.gitignore + Global/macOS.gitignore ``` ```text Technology: Custom Drupal modules ↓ Use: Drupal.gitignore PHP.gitignore (if available, or merge appropriate rules) ``` -------------------------------- ### Gitignore Patterns Matching Zero Paths Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Shows how patterns ending in a slash can match zero directories, enabling more complex exclusion rules. ```gitignore **/test/ # Matches: test/, dir/test/, dir/sub/test/ ``` -------------------------------- ### Download Gitignore Templates via Curl Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use curl to download and append gitignore templates directly to your .gitignore file. The -s flag silences progress meters for the second command. ```bash # Download Python template curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore # Append Global/VisualStudioCode curl -s https://raw.githubusercontent.com/github/gitignore/main/Global/VisualStudioCode.gitignore >> .gitignore ``` -------------------------------- ### Ansible Playbooks .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Global/Ansible.gitignore for projects involving Ansible for configuration management. ```text Technology: Ansible configuration management ↓ Use: Global/Ansible.gitignore ``` -------------------------------- ### Unity Game Development .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Unity.gitignore for Unity game engine projects. If using a JetBrains IDE, also include Global/JetBrains.gitignore. ```text Technology: Unity game engine ↓ Use: Unity.gitignore Global/JetBrains.gitignore (if using JetBrains IDE) ``` -------------------------------- ### Unreal Engine Project .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use UnrealEngine.gitignore for Unreal Engine projects, particularly those using C++. ```text Technology: Unreal Engine (C++) ↓ Use: UnrealEngine.gitignore ``` -------------------------------- ### MkDocs Documentation .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Python.gitignore for MkDocs documentation projects, as it often includes relevant patterns. ```text Technology: MkDocs documentation ↓ Use: Python.gitignore (includes MkDocs patterns) ``` -------------------------------- ### File vs. Directory Matching in Gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Demonstrates how patterns without a trailing slash match both files and directories, while patterns with a trailing slash match only directories. ```gitignore temp # Matches both "temp" file and "temp" directory temp/ # Matches only "temp" directory ``` -------------------------------- ### Run Local Shellcheck Lint Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Performs basic linting on a template file using 'shellcheck', assuming GitBash syntax. ```bash # Lint template (basic checks) shellcheck [template] # If GitBash syntax used ``` -------------------------------- ### Combine Multiple .gitignore Templates Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md This script automates the process of downloading and combining multiple .gitignore templates from the GitHub repository into a single file. It also includes steps to sort and remove duplicate entries. ```bash #!/bin/bash # Script to combine multiple templates TEMPLATES=(Python Node Global/VisualStudioCode Global/macOS) OUTPUT=".gitignore" > "$OUTPUT" # Clear file for template in "${TEMPLATES[@]}"; do curl -s "https://raw.githubusercontent.com/github/gitignore/main/${template}.gitignore" >> "$OUTPUT" echo "" >> "$OUTPUT" # Add blank line between sections done # Remove duplicates (optional, but recommended) sort "$OUTPUT" | uniq > "$OUTPUT.tmp" mv "$OUTPUT.tmp" "$OUTPUT" ``` -------------------------------- ### Verify Gitignore Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use git status --ignored to see all ignored files and git check-ignore -v to verify specific file patterns. ```bash # Check what would be ignored git status --ignored # Verify specific files git check-ignore -v .env.local # Commit the .gitignore file git add .gitignore git commit -m "Add .gitignore from GitHub templates" ``` -------------------------------- ### Run Local Git Ignore Check Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Tests gitignore patterns against sample files using the 'git check-ignore' command. ```bash # Check template syntax (if tools available) git check-ignore -v * # Test patterns against sample files ``` -------------------------------- ### Terraform Project .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Use Terraform.gitignore for projects managed with HashiCorp's Terraform for infrastructure as code. ```text Technology: Terraform (HashiCorp) ↓ Use: Terraform.gitignore ``` -------------------------------- ### Add Node.js to Existing Project Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Append Node.js specific ignore patterns to an existing .gitignore file when adding a Node.js frontend to a project. Includes a command to test the status of ignored files. ```bash # Append Node.gitignore patterns to existing .gitignore curl https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore >> .gitignore # Review for duplicates (Git handles some redundancy, but better clean) # Remove duplicate sections if combined from multiple templates # Test git status --ignored ``` -------------------------------- ### Dependencies/Package Management Section Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Ignores package directories and lockfiles with version-specific content. These directories can be enormous, platform-specific, and regenerated from lockfiles. ```gitignore # Dependencies node_modules/ bower_components/ vendor/ .venv virtualenv/ env/ ``` -------------------------------- ### Template Versioning Structure Source: https://github.com/github/gitignore/blob/main/_autodocs/contributing-and-maintenance.md Illustrates the directory structure for evergreen (current) and versioned (community) templates. ```tree Root (Evergreen - current version) ├── Python.gitignore (current Python patterns) ├── Dotnet.gitignore (current .NET patterns) └── ... Community (Versioned - previous versions) ├── community/DotNet/ │ ├── InforCRM.gitignore │ ├── InforCRM_2.0.gitignore (previous version) │ └── ... └── ... ``` -------------------------------- ### Populate Global Gitignore with Common Patterns Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md Add common ignore patterns for macOS, VS Code, and JetBrains IDEs to your global gitignore file using curl. ```bash # Start with macOS patterns curl https://raw.githubusercontent.com/github/gitignore/main/Global/macOS.gitignore >> ~/.gitignore_global # Add VS Code patterns curl https://raw.githubusercontent.com/github/gitignore/main/Global/VisualStudioCode.gitignore >> ~/.gitignore_global # Add JetBrains IDE patterns curl https://raw.githubusercontent.com/github/gitignore/main/Global/JetBrains.gitignore >> ~/.gitignore_global ``` -------------------------------- ### iOS Development .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md For Swift/Objective-C iOS development, use Swift.gitignore along with Global/Xcode.gitignore. ```text Technology: Swift/Objective-C iOS ↓ Use: Swift.gitignore Global/Xcode.gitignore ``` -------------------------------- ### Add .gitignore to Version Control Source: https://github.com/github/gitignore/blob/main/_autodocs/usage-guide.md This snippet shows how to add the .gitignore file to your Git repository and commit it with a descriptive message. It's recommended to commit .gitignore to ensure consistent ignore rules across all collaborators and environments. ```bash # Add to repository git add .gitignore git commit -m "Add .gitignore from GitHub templates - Python.gitignore for backend dependencies and cache - Node.gitignore for frontend build artifacts - Global/VisualStudioCode.gitignore for IDE settings - Global/macOS.gitignore for OS metadata" ``` -------------------------------- ### Explanatory Comments with Links in .gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/project-overview.md Include optional explanatory comments with external links to provide further context or documentation for specific ignore rules, such as those related to lockfiles. ```gitignore # Optional lockfile # Include these if you want to ensure reproducibility: # - https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control # poetry.lock ``` -------------------------------- ### Gitignore Specificity Levels Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Demonstrates different levels of pattern specificity, from exact filenames to multi-level patterns. ```gitignore # Exact filename build.log ``` ```gitignore # File extension *.log ``` ```gitignore # Entire directory build/ ``` ```gitignore # Pattern in multiple locations **/*.pyc ``` -------------------------------- ### Conservative Pattern Inclusion Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Illustrates the principle of conservatism by including patterns with clear justification and excluding ambiguous ones. Use this approach to avoid accidentally ignoring important files. ```gitignore # Include: *.pyc (generated, never useful) # Exclude: *.txt (might be documentation) ``` -------------------------------- ### Gitignore Comment Conventions Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Use comments to explain byte-compiled files, npm debug logs, cache directories, and Sphinx documentation links. ```gitignore # Byte-compiled / optimized / DLL files ``` ```gitignore # npm debug logs npm-debug.log* ``` ```gitignore # Yarn cache directory .yarn-cache/ ``` ```gitignore # Optional npm cache directory .npm ``` ```gitignore # Optional eslint cache .eslintcache ``` ```gitignore # Sphinx documentation # https://www.sphinx-doc.org/ docs/_build/ ``` -------------------------------- ### Logical Pattern Organization Source: https://github.com/github/gitignore/blob/main/_autodocs/template-structure-analysis.md Shows the principle of maintainability through logical grouping of patterns within sections. This makes the .gitignore file easier to navigate and manage. ```gitignore # Logical grouping [Section 1] pattern pattern [Section 2] pattern pattern ``` -------------------------------- ### Efficient Directory Exclusion in Gitignore Source: https://github.com/github/gitignore/blob/main/_autodocs/gitignore-format-reference.md Demonstrates efficient directory exclusion by ignoring the directory itself rather than its contents. ```gitignore # Efficient: Ignores directory and stops traversal build/ # Less efficient: Git still traverses build/ checking rules build/* build/**/* ```