Git Aliases and Configuration

Set up Git configuration, useful aliases, and a global ignore file so your daily workflow is faster and more consistent.

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`?

Continue Learning

Explore Related Topics

Related Resources