Git Aliases and Configuration

By Vishvesh Patel · DevOps EngineerUpdated September 16, 2026

Configure Git once and stop fighting it. Config scopes, per-directory work identities, aliases worth having, and the defaults to change.

Why Git Configuration Matters

Git works immediately, but a small amount of configuration makes daily work much smoother. Good defaults reduce mistakes, remove repeated typing, and help keep your environment consistent across projects.

In this lesson, you will cover:

  • config scopes
  • identity settings
  • editor and default branch setup
  • useful aliases
  • a global ignore file

Tip: Start with a few settings you use every day. You do not need a giant .gitconfig to get real value.

Understanding .gitconfig Scopes

Git reads settings from three main levels:

  • system: for all users on the machine
  • global: for your user account
  • local: for one repository only

Most personal preferences belong in global config, while project-specific exceptions belong in local config.

Useful commands:

git config --list
git config --list --show-origin

Typical files are:

  • /etc/gitconfig
  • ~/.gitconfig
  • .git/config

Local settings override global ones, and global settings override system ones.

Setting Name and Email

Git writes author information into each commit, so configure identity first.

git config --global user.name "Vishvesh Patel"
git config --global user.email "vishvesh@example.com"

Verify the values:

git config --global user.name
git config --global user.email

If one repository needs a different email, set it locally:

cd company-project
git config user.email "vishvesh@company.com"

Default Editor and Default Branch

Git may open an editor for commit messages, rebases, or merge messages. Pick one you already use.

git config --global core.editor "code --wait"

Or:

git config --global core.editor "vim"

To make new repositories start on main:

git config --global init.defaultBranch main

Note: This affects only future git init repositories. Existing repositories keep their current branch names until you rename them.

Reading a .gitconfig File

A .gitconfig file is a simple INI-style file.

[user]
  name = Vishvesh Patel
  email = vishvesh@example.com
[core]
  editor = code --wait
[init]
  defaultBranch = main

You can edit it directly or let git config write the entries for you.

Useful Git Aliases

Aliases turn longer commands into shorter ones.

Basic examples:

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit

That lets you run:

git st
git co main
git br

Pretty Log Alias

A compact history view is one of the most useful aliases you can add.

git config --global alias.lg "log --oneline --graph --decorate --all"

Then run:

git lg

Workflow Aliases

A few more practical shortcuts:

git config --global alias.last "log -1 HEAD"
git config --global alias.unstage "restore --staged"
git config --global alias.amend "commit --amend"

Aliases should make common work faster, not hide commands you do not understand.

Using a Global Ignore File

Some files should stay out of git status in every repository, such as:

  • .DS_Store
  • editor folders like .vscode/
  • swap files
  • local-only secret files

Create a personal ignore file:

touch ~/.gitignore_global

Example contents:

.DS_Store
.vscode/
*.swp
.env.local

Tell Git to use it:

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

This keeps machine-specific clutter out of all repositories without editing each project's .gitignore.

A Simple Starter Setup

git config --global user.name "Vishvesh Patel"
git config --global user.email "vishvesh@example.com"
git config --global core.editor "code --wait"
git config --global init.defaultBranch main
git config --global core.excludesfile ~/.gitignore_global
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 --decorate --all"

What You Should Remember

Git configuration lives at system, global, and local levels. Set your identity, choose a comfortable editor, define main as the default branch for new repositories, add a few aliases, and use a global ignore file for OS and editor clutter. Small config improvements make Git easier every day.

Test Your Understanding

Exercise

Exercise 1: Picking the right config scope

Which Git configuration scope should you use for a custom email address that only applies to one specific repository?

Exercise

Exercise 2: Understanding aliases

After running `git config --global alias.st status`, what does `git st` do?

Exercise

Exercise 3: Global ignore behavior

Why would you use `~/.gitignore_global` with `core.excludesfile`?


Frequently Asked Questions

Where is my .gitconfig file and what are the config scopes?

There are three, each overriding the one above. System config applies to every user on the machine (/etc/gitconfig, edited with --system). Global config is yours (~/.gitconfig, edited with --global) and is where nearly everything belongs. Local config belongs to one repository (.git/config, the default with no flag) and is what you use to override your identity for a single project. git config --list --show-origin prints every setting alongside the file it came from, which settles most "why is this value set" questions.

How do I use a different email for work and personal repositories?

Set the work identity per repository with git config user.email you@company.com, which writes to that repository's .git/config and overrides your global value. For more than a couple of repositories, use conditional includes: in ~/.gitconfig, an [includeIf "gitdir:~/work/"] section pointing at a second config file applies automatically to anything under that directory. That way a new clone in the right folder gets the right identity without you remembering to set it.

How do I create a Git alias?

git config --global alias.<name> '<command>', so git config --global alias.st status gives you git st. Aliases can chain flags, as with a pretty log: alias.lg "log --oneline --graph --decorate --all". Prefixing the value with ! runs a shell command rather than a Git subcommand, which lets an alias combine several steps. Aliases live in your config, so they are yours alone and do not travel with the repository.

Which Git aliases are actually worth setting up?

Start with the ones you type dozens of times a day, st for status, co for checkout or switch, br for branch, ci for commit. Then add the ones whose full form you would never type: a graph log, last for log -1 HEAD, and unstage for restore --staged. Do not alias destructive commands to short names; a two-character alias for reset --hard is an accident waiting to happen.

What is a global gitignore and why use one?

A .gitignore in the repository describes what that project should not track, and belongs in version control. A global ignore file, set with git config --global core.excludesfile ~/.gitignore_global, covers things specific to you: .DS_Store, editor directories such as .idea/ and .vscode/, and local scratch files. The distinction matters as courtesy: your colleagues on other systems should not have to carry ignore rules for your operating system and editor.

What Git settings should everyone change from the defaults?

Four are worth setting immediately. init.defaultBranch main, so new repositories match what hosting platforms expect. pull.rebase true, which stops a plain git pull littering history with merge commits. fetch.prune true, so branches deleted upstream disappear from your local list. And core.editor set to something you can exit, which spares you meeting Vim unexpectedly. Adding rerere.enabled true pays for itself the first time you rebase through the same conflict twice.

Continue Learning

Explore Related Topics

When it breaks

Related Resources