Create a .gitignore skeleton, optionally initialize a git repository, and install a secret-scanning pre-commit hook.
No external dependencies, all self-contained, all Python. You're not you without version control, eat a Newgit
If you have the Python script:
./newgit.py [path]If you have the compiled binary:
./newgit [path]If path is omitted, it uses the current directory.
Create .gitignore in the current directory and prompt for git init:
./newgit.pyCreate .gitignore in a new project directory:
./newgit.py ~/projects/my-appOverride the ignore patterns for a single run. Put the path before -i if you also pass a directory:
./newgit.py -i .venv/ node_modules/ __pycache__/
./newgit.py ~/projects/my-app -i .venv/ node_modules/Skip the git init prompt and always run it:
./newgit.py --git-initSkip the git init prompt and never run it:
./newgit.py --no-git-initForce the built-in defaults even if a config file exists:
./newgit.py --defaultsSkip the pre-commit hook installation when running git init:
./newgit.py --git-init --no-precommitCreate an AGENTS.md skeleton that instructs coding agents never to run ANY git commands (including read-only ones like git status, and indirect use via scripts or subagents):
./newgit.py ~/projects/my-app --agent-md --no-git-initIf AGENTS.md already exists, it is left untouched. See also the agent_md / no_agent_md config keys below.
The generated .gitignore includes common build, IDE, and macOS artifacts, plus secret- and credential-related files:
# Editor / IDE
.cursor/
# Agent skills
/SKILL.md
# Build / debug artifacts
.build/
.debug/
# macOS
.DS_Store
# Secrets and credentials
.env
.env.*
!.env.example
*.pem
*.key
*.p12
*.pfx
*.keystore
*.jks
id_rsa
id_rsa.pub
id_dsa
id_dsa.pub
id_ecdsa
id_ecdsa.pub
id_ed25519
id_ed25519.pub
secrets/
credentials/
private/
You can provide a persistent list of ignore patterns in a config file:
$XDG_CONFIG_HOME/newgit/ignore~/.config/newgit/ignore(fallback)
The file uses one pattern per line. Lines starting with # and blank lines are ignored. If the file exists, it replaces the built-in defaults. Use --defaults to ignore the config file.
All optional flags can also be configured via a newgit.yml file. newgit looks for it first in the target directory, then in the global config directory ($XDG_CONFIG_HOME/newgit/newgit.yml or ~/.config/newgit/newgit.yml).
Supported keys (all optional):
| Key | Type | Description |
|---|---|---|
path |
string | Target directory (default: .) |
ignore |
list | Ignore patterns to write |
defaults |
boolean | Use built-in defaults instead of config file |
no_precommit |
boolean | Do not install the secret-scanning pre-commit hook |
git_init |
boolean | Run git init without prompting |
no_git_init |
boolean | Do not run git init |
agent_md |
boolean | Create an AGENTS.md skeleton forbidding any git commands (default: false) |
no_agent_md |
boolean | Do not create AGENTS.md |
Example newgit.yml:
path: .
ignore:
- .venv/
- node_modules/
- __pycache__/
- .DS_Store
git_init: true
no_precommit: falseCLI arguments override newgit.yml values. --defaults still forces the built-in ignore patterns regardless of the config file. git_init and no_git_init cannot both be set to true, and agent_md and no_agent_md cannot both be set to true.
The inline parser supports a small YAML subset: top-level keys, block lists, quoted strings, booleans, numbers, and null. Flow lists (e.g. ignore: [a, b]) and block scalars (|, >) are parsed only on a best-effort basis.
If the target directory already contains a .gitignore, the tool prompts:
.gitignore already exists. [o]verwrite / [a]ppend / [q]uit:
Append mode merges the resolved patterns into the existing file, skipping duplicates.
When git init is run (or when you run newgit inside an existing repository), it offers to install a pre-commit hook in .git/hooks/pre-commit. The hook scans staged files for:
- Private key blocks (
-----BEGIN ... PRIVATE KEY-----) - AWS access key IDs (
AKIA...) - Lines containing
api_key,secret_key,private_key,auth_token, oraccess_tokenfollowed by a value - Provider-specific key formats for OpenAI, Anthropic, Cursor, DeepSeek, Kimi/Moonshot, and Z.ai (including
sk-...,key_..., and Z.aiid.secretkeys) - Sensitive filenames such as
.env,.pem,.key,.p12,.pfx,.keystore, and.jks
If it finds any of these, the commit is blocked and the offending lines are printed. The hook is written in Python and requires python3 to be available in the environment where commits are made.
You can build a single-file executable for Linux or macOS with PyInstaller.
Install PyInstaller (once):
pip install pyinstallerBuild the binary:
makeThe resulting executable is written to dist/newgit. You can run it directly or copy it to a directory on your PATH:
./dist/newgit --help
cp dist/newgit /usr/local/bin/newgitTo clean build artifacts:
make cleanNotes:
- PyInstaller binaries are platform-specific. Run
makeon each platform where you need a binary (e.g., macOS for macOS, Linux for Linux). make installcopiesdist/newgitto/usr/local/bin/newgit.
