Git Configuration
Sensible Git defaults and aliases save Rust teams hours: rebase pulls, helpful logs, hooks that mirror CI, and global ignores for target/ artifacts.
Search across all documentation pages
Sensible Git defaults and aliases save Rust teams hours: rebase pulls, helpful logs, hooks that mirror CI, and global ignores for target/ artifacts.
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global fetch.prune true
git config --global rerere.enabled true
git config --global alias.st 'status -sb'
git config --global alias.lg "log --oneline --graph -20"
git config --global alias.fp 'push --force-with-lease'When to reach for this:
cargo fmt and clippy# ~/.gitignore_global
target/
**/*.rs.bk
.env
.env.*
!.env.examplegit config --global core.excludesfile ~/.gitignore_global# .pre-commit-config.yaml (repo)
repos:
- repo: local
hooks:
- id: rustfmt
name: rustfmt
entry: cargo fmt --all --
language: system
pass_filenames: false
- id: clippy
name: clippy
entry: cargo clippy --all-targets -- -D warnings
language: system
pass_filenames: falseWhat this demonstrates:
target/ accidentsrerere reuses recorded conflict resolutions| Setting | Effect |
|---|---|
merge.conflictstyle zdiff3 | Shows common ancestor in conflicts |
push.autoSetupRemote true | First push sets upstream |
core.autocrlf input | LF line endings on macOS/Linux |
# .gitmessage
# <type>(<scope>): <subject> [TICKET]
#
# body: why, not what
git config commit.template .gitmessage
--no-verify every commit. Fix: fix slow hooks, do not disable.ssh-keygen and GitHub signing setup early.core.autocrlf surprises in CI. Fix: .gitattributes * text=auto eol=lf.| Alternative | Use When | Don't Use When |
|---|---|---|
lefthook | Cross-language monorepo hooks | Simple Rust-only repo |
husky | JS+Rust polyglot | Pure Rust |
| Manual CI only | Zero local hook friction | Style drift before push |
Identity and aliases global; hook versions local per repo for reproducibility.
git config --global credential.helper osxkeychain.
Use Git LFS for binaries; prefer building release artifacts in CI instead of committing them.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 16, 2026