Customizing Git Behavior: Configuration, Aliases, and Important Files
Customize Git with useful config settings, clear aliases, and key files like .gitignore and .gitattributes.
Customizing Git Behavior: Configuration, Aliases, and Important Files
Customizing Git behavior helps you make everyday version control faster, safer, and more predictable. With the right Git configuration, aliases, and important files in place, your local workflow can match how your team actually builds software.
The goal is not to create a clever setup nobody else understands. The goal is to remove friction from common tasks while keeping your repositories easy to audit and support.
How Git Configuration Works
Git reads settings from several places, and the closer setting wins. That matters when you are debugging why Git uses the wrong name, editor, merge tool, line endings, or signing behavior.
The three main configuration scopes are:
- System: applies to every user on the machine.
- Global: applies to your user account.
- Local: applies only to the current repository.
You will usually work with global and local settings. Global settings are good for your identity, default editor, and common aliases. Local settings are better for repository-specific behavior, such as a different email address for work projects.
Use these commands to inspect where a setting comes from:
git config --list --show-origin
git config user.email
git config --local user.email
git config --global user.email
For example, you might use your personal email globally:
git config --global user.name "Alex Morgan"
git config --global user.email "[email protected]"
Then, inside a work repository, override only the email:
git config --local user.email "[email protected]"
This avoids accidentally committing to a company repository with a personal identity. It also makes commit history cleaner for compliance, ownership, and code review.
If you want a deeper refresher on identity settings, see mastering Git user configuration.
Useful Settings to Customize First
Start with settings that improve clarity and prevent small mistakes. You do not need a huge configuration file to get real value.
A good baseline includes your default branch name:
git config --global init.defaultBranch main
Set your preferred editor so Git can open commit messages, rebase plans, and merge notes in a tool you actually use:
git config --global core.editor "code --wait"
If you work across macOS, Linux, and Windows, line endings deserve attention. Many teams choose to keep line endings normalized in the repository and let each developer's editor handle display. A common Windows setting is:
git config --global core.autocrlf true
On macOS or Linux, teams often use:
git config --global core.autocrlf input
Do not change line-ending settings casually in an existing repository. If you see a huge diff where every line appears modified, stop and inspect .gitattributes before committing.
You can also make Git's output more readable:
git config --global color.ui auto
git config --global column.ui auto
git config --global branch.sort -committerdate
git config --global tag.sort version:refname
For pulling changes, choose the behavior your team expects:
git config --global pull.rebase false
or:
git config --global pull.rebase true
Neither option is universally correct. Merge-based pulls preserve merge commits. Rebase-based pulls keep a linear local history. The important part is choosing intentionally and documenting team expectations.
Creating Git Aliases That Save Time
Git aliases turn long commands into short, memorable shortcuts. They are especially useful for commands you run many times a day.
Here are practical aliases that stay readable:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
git config --global alias.last "log -1 HEAD --stat"
git config --global alias.unstage "restore --staged"
After that, git st gives you status and git unstage file.txt removes a file from the staging area without touching your working copy.
Log aliases are where many teams get the most value:
git config --global alias.lg "log --oneline --decorate --graph --all"
Now you can run:
git lg
This gives you a compact graph of branches, tags, and commits. It is useful before rebasing, merging, or cleaning up local branches.
Keep aliases boring enough that a teammate can guess what they do. An alias like git save might mean commit, stash, or something else depending on the person who created it. An alias like git unstage is obvious.
You can review your aliases with:
git config --global --get-regexp '^alias\.'
For more examples, see create custom Git aliases.
Important Git Files You Should Know
Git behavior is not controlled only by git config. Several repository files shape what gets tracked, ignored, normalized, and protected.
The most common file is .gitignore. It tells Git which untracked files to ignore. Typical entries include build output, local environment files, editor folders, and dependency caches:
node_modules/
dist/
.env
.DS_Store
Be careful with broad patterns. Ignoring *.json might hide generated files, but it can also hide important configuration. When possible, ignore specific directories or filenames.
The .gitattributes file controls how Git treats file types. It is useful for line endings, generated files, linguist behavior, and merge strategies:
* text=auto
*.sh text eol=lf
*.bat text eol=crlf
This is especially helpful in teams using different operating systems. It reduces noisy diffs and keeps scripts from breaking because of the wrong line endings.
The .git/config file stores local repository configuration. You normally edit it with git config --local, but reading it can help you troubleshoot remotes, branch tracking, and repository-specific options.
Git hooks live under .git/hooks/. They can run scripts before commits, pushes, merges, and other events. By default, hooks are local and not committed as active scripts. Teams that rely on hooks often use a setup script or a hook manager to install them consistently.
When to Ask for Help
Most Git configuration changes are safe, but some can disrupt a team if applied without context. Ask a senior engineer, DevOps engineer, or repository owner before changing line-ending rules, merge drivers, signing requirements, or shared hook behavior.
You should also get help if commits are appearing with the wrong identity in a protected repository. Fixing author metadata after code has been pushed can require history rewriting, which affects everyone using that branch.
If Git suddenly behaves differently, start with git config --list --show-origin. That one command often explains the mystery faster than guessing.
Thoughtful customization makes Git feel less repetitive without hiding what is happening. Keep your aliases clear, keep repository rules documented, and use local settings when one project needs different behavior from the rest of your machine.