PowerShell 7+ script that silently drops a
.gitignore
into every new repo right aftergit init
. Handlesgit init <dir>
, multiple-C
flags, and skips--bare
. Never overwrites an existing file.
- Zero-friction: keep using
git init
as usual - Silent by default; optional DEBUG and diagnostics
- Cross-platform in PowerShell 7+ (Windows/macOS/Linux)
- PowerShell 7+
- Git on
PATH
- Open your profile and paste the script at the end (after any modules).
notepad $PROFILE
β paste β save Reload:. $PROFILE
- Create a template (one-time):
- Put a file at
$HOME\.git-templates\.gitignore
, or - Run:
New-GitIgnoreTemplate -UseGitConfig -SetEnvironment
- Put a file at
- Standard:
git init
- Target dir:
git init MyRepo
- With
-C
:git -C C:\work init
- Bare repos are skipped:
git init --bare Repo.git
The script never overwrites an existing
.gitignore
. To overwrite manually:Copy-GitIgnoreFromTemplate -WorkTree . -Force
- Toggle debug:
$Global:GIT_INIT_WRAPPER_DEBUG = $true
- Show search order and the picked template:
Show-GitIgnoreTemplatePaths
New-GitIgnoreTemplate [-UseGitConfig] [-SetEnvironment] [-Path <file>]
Get-GitIgnoreTemplatePaths [-Refresh]
Show-GitIgnoreTemplatePaths
Copy-GitIgnoreFromTemplate -WorkTree <dir> [-Force]
- Fork β branch β PR
- Keep changes minimal and well-commented
- Add/update tests/instructions if behavior changes
This project is licensed under the MIT License