Master Git in 30 Days

Day 14: Git for Windows Configuration Options

Using Git for Windows command-line tools is definitely more efficient than operating through GUI tools. The reason is that you can automate many repetitive version control tasks through commands, or transform complex standard operating procedures (SOPs) into simple command operations. This article will share some tips for using Git for Windows command-line tools.

About Git Command-Line Tool Configuration Options

In Git command-line tools, there are many “options” that can be set, just like we usually have [Tools] -> [Preferences] when using GUI tools, to fine-tune some behaviors when commands are executed. The most common, of course, is when you first use Git for Windows, you must set the user.name and user.email options. Without these two options set, you don’t even have the right to execute git commit.

To list all options currently set in Git for Windows tools, you can use the git config --list command.

Note: Since most Git articles on the internet introduce how to set up Linux or Mac environments, my article will focus on Windows platform configuration. However, except for the storage path being different, the usage of commands is actually the same.

If you want to check what “options” are available, you can execute git help config at the command prompt to display complete documentation or visit the git-config(1) Manual Page.

Understanding Git Configuration Levels

Git has three levels of configuration:

  1. System level (--system): Applies to all users on the system
    • Location: C:\Program Files\Git\etc\gitconfig
    • Important for Windows: With UAC enabled, settings may be redirected to %LOCALAPPDATA%\VirtualStore\Program Files\Git\etc\gitconfig
    • Recommendation: Always run Command Prompt as Administrator when setting system-level options
  2. Global level (--global): Applies to the current user
    • Location: C:\Users\[username]\.gitconfig or %USERPROFILE%\.gitconfig
    • Commonly used for user.name, user.email, and personal preferences
  3. Local level (--local): Applies only to the current repository
    • Location: .git\config in the repository
    • Created automatically when you initialize or clone a repository

Configuration at lower levels overrides higher levels (local > global > system).

Viewing Configuration

To view all current configurations:

git config --list

To view configuration from a specific level:

git config --global --list
git config --local --list
git config --system --list

Setting User Identity

The most basic configuration is setting your user name and email:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

These settings are used in every commit you make.

Configuring Default Editor

Set your preferred text editor for commit messages:

git config --global core.editor "code --wait"  # VS Code
git config --global core.editor "notepad"      # Notepad
git config --global core.editor "vim"          # Vim

Line Ending Configuration

This is important for cross-platform development:

# Windows (convert LF to CRLF on checkout, CRLF to LF on commit)
git config --global core.autocrlf true

# Linux/Mac (convert CRLF to LF on commit, no conversion on checkout)
git config --global core.autocrlf input

# No conversion
git config --global core.autocrlf false

Important: Windows UAC and VirtualStore

On Windows Vista and later with User Account Control (UAC) enabled, there’s an important consideration when setting system-level configuration:

The Problem: Windows VirtualStore technology redirects file writes when non-administrator processes try to write to system directories. This means:

  • Settings made with normal Command Prompt go to %LOCALAPPDATA%\VirtualStore\Program Files\Git\etc\gitconfig
  • Settings made with Administrator Command Prompt go to C:\Program Files\Git\etc\gitconfig
  • These two locations don’t sync, causing unexpected behavior

The Solution: When setting system-level options (--system), always run Command Prompt as Administrator to ensure settings apply system-wide.

For more information: VirtualStore - Inside Windows Vista User Account Control

Configuring Aliases

Create shortcuts for commonly used commands:

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.lg "log --oneline --graph --all"

Then you can use git co instead of git checkout, etc.

Color Output

Enable colored output for better readability:

git config --global color.ui auto

Default Branch Name

Set the default branch name for new repositories:

git config --global init.defaultBranch main

Merge and Diff Tools

Configure your preferred merge and diff tools:

git config --global merge.tool vimdiff
git config --global diff.tool vimdiff

Credential Helper

Store credentials to avoid repeated password entry:

# Windows
git config --global credential.helper wincred

# Cache credentials for 1 hour
git config --global credential.helper 'cache --timeout=3600'

Push Behavior

Configure default push behavior:

# Push only the current branch
git config --global push.default simple

# Push all matching branches
git config --global push.default matching

Unset Configuration

To remove a configuration:

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

Editing Configuration Files Directly

You can also edit configuration files directly:

git config --global --edit
git config --local --edit

Today’s Summary

Understanding and properly configuring Git is essential for a smooth workflow. The configuration system is flexible and powerful, allowing you to customize Git to match your preferences and working environment.

Let me reorganize the Git commands and parameters learned today:

  • git config –list
  • git config –global user.name
  • git config –global user.email
  • git config –global core.editor
  • git config –global core.autocrlf
  • git config –global alias.*
  • git config –global –edit
  • git config –global –unset