|
| 1 | +--- |
| 2 | +title: "gh-templates gitignore add" |
| 3 | +sidebar_label: "gitignore add" |
| 4 | +--- |
| 5 | + |
| 6 | +# Add Gitignore Templates |
| 7 | + |
| 8 | +Add one or more gitignore templates to your repository. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +```bash |
| 13 | +gh-templates gitignore add [OPTIONS] [TEMPLATE]... |
| 14 | +``` |
| 15 | + |
| 16 | +## Arguments |
| 17 | + |
| 18 | +| Argument | Description | |
| 19 | +|-----------------|------------------------------------------------------------------| |
| 20 | +| `[TEMPLATE]...` | Gitignore template names to add (e.g., rust, python, global/windows) | |
| 21 | + |
| 22 | +## Options |
| 23 | + |
| 24 | +| Option | Description | |
| 25 | +|-------------------------------|-----------------------------------------------------------------------------| |
| 26 | +| `--dir <DIR>` | Directory to save the `.gitignore` file | |
| 27 | +| `--force` | Force overwrite existing `.gitignore` file | |
| 28 | +| `--all` | Download all available templates | |
| 29 | +| `-a, --append` | Append to the existing `.gitignore` file instead of overwriting | |
| 30 | +| `--update-cache` | Update the gitignore template cache | |
| 31 | +| `-n, --use-remote-name` | Use the remote template file name as the output file name | |
| 32 | +| `-o, --output <FILENAME>...` | Output file name(s) (default: `.gitignore`) | |
| 33 | +| `-h, --help` | Print help | |
| 34 | + |
| 35 | +## Examples |
| 36 | + |
| 37 | +### Add a Single Template |
| 38 | + |
| 39 | +```bash |
| 40 | +gh-templates gitignore add rust |
| 41 | +``` |
| 42 | + |
| 43 | +Downloads the Rust gitignore template and saves it as `.gitignore` in the repository root. |
| 44 | + |
| 45 | +### Add Multiple Templates |
| 46 | + |
| 47 | +```bash |
| 48 | +gh-templates gitignore add rust docker vscode |
| 49 | +``` |
| 50 | + |
| 51 | +Combines multiple gitignore templates into a single comprehensive file. |
| 52 | + |
| 53 | +### Custom Output Directory |
| 54 | + |
| 55 | +```bash |
| 56 | +gh-templates gitignore add python --dir backend/ |
| 57 | +``` |
| 58 | + |
| 59 | +Saves the gitignore file to a custom directory (useful for monorepos). |
| 60 | + |
| 61 | +### Custom File Names |
| 62 | + |
| 63 | +```bash |
| 64 | +gh-templates gitignore add rust python -o .gitignore.rust -o .gitignore.python |
| 65 | +``` |
| 66 | + |
| 67 | +Creates separate gitignore files for each template. |
| 68 | + |
| 69 | +### Force Overwrite |
| 70 | + |
| 71 | +```bash |
| 72 | +gh-templates gitignore add node --force |
| 73 | +``` |
| 74 | + |
| 75 | +Overwrites existing `.gitignore` file without prompting. |
| 76 | + |
| 77 | +### Add All Templates |
| 78 | + |
| 79 | +```bash |
| 80 | +gh-templates gitignore add --all |
| 81 | +``` |
| 82 | + |
| 83 | +Downloads and combines all available gitignore templates (creates a very comprehensive file ~ Not Recommended). |
| 84 | + |
| 85 | +### Append to Existing File |
| 86 | + |
| 87 | +```bash |
| 88 | +gh-templates gitignore add python --append |
| 89 | +``` |
| 90 | + |
| 91 | +Appends the Python template to the existing `.gitignore` file. |
| 92 | + |
| 93 | +### Use Remote Template Name |
| 94 | + |
| 95 | +```bash |
| 96 | +gh-templates gitignore add rust -n |
| 97 | +``` |
| 98 | + |
| 99 | +Saves the template using its remote file name (e.g., `Rust.gitignore`). |
| 100 | + |
| 101 | +### Update Template Cache |
| 102 | + |
| 103 | +```bash |
| 104 | +gh-templates gitignore add --update-cache |
| 105 | +``` |
| 106 | + |
| 107 | +Updates the local cache of available gitignore templates. |
| 108 | + |
| 109 | +### Complex Example |
| 110 | + |
| 111 | +```bash |
| 112 | +gh-templates gitignore add rust docker windows --dir . --force -o .gitignore |
| 113 | +``` |
| 114 | + |
| 115 | +This command: |
| 116 | + |
| 117 | +- Adds Rust, Docker, and Windows gitignore patterns |
| 118 | +- Saves to repository root directory |
| 119 | +- Forces overwrite of existing file |
| 120 | +- Uses explicit output filename |
| 121 | + |
| 122 | +## Default Behavior |
| 123 | + |
| 124 | +- **Output Directory**: Repository root (`.`) |
| 125 | +- **File Names**: `.gitignore` (single file containing all patterns) |
| 126 | +- **Overwrite**: Prompts before overwriting existing files (unless `--force` is used) |
| 127 | +- **Append**: By default, overwrites unless `--append` is specified |
| 128 | +- **Combination**: Multiple templates are merged into one file |
| 129 | + |
| 130 | +## Template Combination |
| 131 | + |
| 132 | +When adding multiple templates, `gh-templates` intelligently combines them: |
| 133 | + |
| 134 | +1. **Categorization**: Groups patterns by category with comments |
| 135 | + |
| 136 | +## Best Practices for Combining |
| 137 | + |
| 138 | +### Language + OS + Editor |
| 139 | + |
| 140 | +```bash |
| 141 | +gh-templates gitignore add python windows vscode |
| 142 | +``` |
| 143 | + |
| 144 | +### Full Stack Project |
| 145 | + |
| 146 | +```bash |
| 147 | +gh-templates gitignore add javascript python docker |
| 148 | +``` |
| 149 | + |
| 150 | +### Polyglot Repository |
| 151 | + |
| 152 | +```bash |
| 153 | +gh-templates gitignore add rust go python java |
| 154 | +``` |
| 155 | + |
| 156 | +## Monorepo Strategy |
| 157 | + |
| 158 | +For monorepos with multiple projects: |
| 159 | + |
| 160 | +```bash |
| 161 | +# Root-level common ignores |
| 162 | +gh-templates gitignore add windows macos linux |
| 163 | + |
| 164 | +# Language-specific ignores in subdirectories |
| 165 | +gh-templates gitignore add rust --dir rust-service/ |
| 166 | +gh-templates gitignore add node --dir web-frontend/ |
| 167 | +gh-templates gitignore add python --dir python-api/ |
| 168 | +``` |
| 169 | + |
| 170 | +## Updating Gitignore |
| 171 | + |
| 172 | +To update an existing `.gitignore`: |
| 173 | + |
| 174 | +1. **Preview changes** first: |
| 175 | + |
| 176 | + ```bash |
| 177 | + gh-templates gitignore preview rust |
| 178 | + ``` |
| 179 | + |
| 180 | +2. **Backup existing** file: |
| 181 | + |
| 182 | + ```bash |
| 183 | + cp .gitignore .gitignore.backup |
| 184 | + ``` |
| 185 | + |
| 186 | +3. **Update with force**: |
| 187 | + |
| 188 | + ```bash |
| 189 | + gh-templates gitignore add rust --force |
| 190 | + ``` |
| 191 | + |
| 192 | +## Common Combinations |
| 193 | + |
| 194 | +| Project Type | Recommended Templates | |
| 195 | +|-------------------|-----------------------------| |
| 196 | +| Rust desktop app | `rust windows macos linux` | |
| 197 | +| Python web app | `python docker vscode` | |
| 198 | +| Node.js project | `node windows macos` | |
| 199 | +| Full-stack app | `javascript python docker` | |
| 200 | +| Mobile app | `java kotlin swift xcode` | |
| 201 | +| Data science | `python jupyter r` | |
| 202 | + |
| 203 | +## Troubleshooting |
| 204 | + |
| 205 | +### File Already Exists |
| 206 | + |
| 207 | +Without `--force`, you'll be prompted to overwrite. Options: |
| 208 | + |
| 209 | +- Use `--force` to overwrite |
| 210 | +- Use `--append` to add to the existing file |
| 211 | +- Use different output name with `-o` |
| 212 | +- Manually merge the content |
| 213 | + |
| 214 | +### Patterns Not Working |
| 215 | + |
| 216 | +If ignore patterns aren't working: |
| 217 | + |
| 218 | +1. Ensure file is named `.gitignore` |
| 219 | +2. Check file is in repository root or appropriate subdirectory |
| 220 | +3. Commit the `.gitignore` file |
| 221 | +4. Use `git rm --cached <file>` to untrack already-tracked files |
| 222 | + |
| 223 | +## Tips |
| 224 | + |
| 225 | +1. **Start Early**: Add `.gitignore` before committing code |
| 226 | +2. **Be Specific**: Choose templates that match your actual tech stack |
| 227 | +3. **Review Content**: Preview templates to understand what they ignore |
| 228 | +4. **Combine Wisely**: Don't add unnecessary templates that create noise |
| 229 | +5. **Update Regularly**: Refresh gitignore as your project evolves |
0 commit comments