DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Git Tutorial

Introduction to Git
Installing Git
Git Basics
Git Branching
Git Merging
Git Rebasing
Git Remote
Git Stash
Undoing Changes in Git
Git Tagging
GitHub Workflow with Git
Advanced Git
Git Hooks
Git Workflows
Git Aliases and Configuration
Git Submodules
Git Commit Messages

Git Aliases and Configuration

PreviousPrev
Next

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

PreviousPrev
Next

Continue Learning

Advanced Git

Explore useful advanced Git tools including cherry-pick, bisect, reflog, submodules, hooks, and aliases for smarter daily workflows.

25 min·Hard

Git Hooks

Learn how Git hooks automate checks before commits and pushes, and how tools like Husky make hooks shareable across teams.

20 min·Medium

Git Workflows

Compare GitFlow, GitHub Flow, and Trunk-Based Development so you can choose a branching model that fits your team and delivery style.

22 min·Medium

Explore Related Topics

CI

CI/CD Tutorials

Trigger automated pipelines from Git workflows

Li

Linux Tutorials

Use Git effectively on the Linux command line

On This Page

Why Git Configuration MattersUnderstanding `.gitconfig` ScopesSetting Name and EmailDefault Editor and Default BranchReading a `.gitconfig` FileUseful Git AliasesPretty Log AliasWorkflow AliasesUsing a Global Ignore FileA Simple Starter SetupWhat You Should RememberTest Your Understanding