git Distributed version control system, created by Linus Torvalds

Configuration

Configuration levels

Git reads config from three (or four) increasingly specific levels, each overriding the last:

LevelFlagFile
System--system/etc/gitconfig
Global (user)--global~/.gitconfig
Local (repository)--local (default).git/config
Worktree--worktree.git/config.worktree (needs extensions.worktreeConfig)
git config --list --show-origin     # see every setting and where it came from
git config user.email               # read one value (checks all levels)
git config --global --edit          # open ~/.gitconfig in $EDITOR

Commonly changed settings

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "nano"
git config --global pull.rebase true         # pull always rebases instead of merging
git config --global push.autoSetupRemote true # first push of a branch auto-sets upstream
git config --global core.autocrlf input       # line-ending normalization (Linux/macOS)
git config --global color.ui auto

Aliases

Shorten frequently-typed commands:

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all"
git config --global alias.last "log -1 HEAD"

Then git st works exactly like git status. These live under [alias] in ~/.gitconfig and can also be edited there directly.

.gitignore

Patterns of files Git should never track, one per line, checked in at the repository root (or any subdirectory, for scoped rules):

*.log            # wildcard by extension
/build/          # only the top-level build directory
node_modules/    # anywhere in the tree
!important.log   # negate a previous pattern

A personal, global ignore file (for editor swap files, OS cruft, etc.) that applies across every repository on your machine:

git config --global core.excludesFile ~/.gitignore_global

.gitattributes

Controls how Git treats specific paths — line endings, diff behavior, merge strategy, and marking generated files:

*.sh text eol=lf
*.png binary
*.min.js linguist-generated
pubspec.lock merge=ours

Credential helpers

Avoid retyping a personal access token on every HTTPS push:

# Linux, cache in memory for 15 minutes
git config --global credential.helper cache

# Linux, persistent (uses libsecret / gnome-keyring)
git config --global credential.helper libsecret

# macOS
git config --global credential.helper osxkeychain

# Windows
git config --global credential.helper manager