Skip to main content

Git Global Config

Introduction​

When working with Git, you'll want to customize your environment to suit your preferences and workflow. Git allows you to configure settings at three different levels: system, global, and local. In this guide, we'll focus on global configuration, which applies settings to all repositories for your user account on a given system.

Global configurations are stored in a file called .gitconfig in your home directory (~/.gitconfig on Unix-like systems or C:\Users\<username>\.gitconfig on Windows). These settings act as defaults for all your Git repositories but can be overridden by local repository-specific configurations.

Understanding Git Global Config​

Global configuration is particularly useful for setting up your identity, preferred editor, and default behaviors that you want to apply consistently across all your Git projects.

Setting Up Your Global Configuration​

Basic Identity Configuration​

The first thing you should do after installing Git is to set your user name and email address. These details are used by Git to identify who made each commit:

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

Let's see what happens when you run these commands:

Input:

bash
git config --global user.name "John Doe"
git config --global user.email "john.doe@example.com"

Output: There is no visible output, but the settings are saved to your global config file.

You can verify your settings with:

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

Output:

John Doe
john.doe@example.com

Configuring Your Default Editor​

Git often needs to open a text editor for commit messages and other operations. By default, Git uses your system's default editor, but you can specify a different one:

bash
git config --global core.editor "code --wait"  # For Visual Studio Code
# OR
git config --global core.editor "vim" # For Vim
# OR
git config --global core.editor "nano" # For Nano

Setting Default Branch Name​

Recent versions of Git allow you to set the default branch name for new repositories:

bash
git config --global init.defaultBranch main

This will set the default branch name to main instead of master for all new repositories you initialize.

Viewing Your Global Configuration​

To view all your global Git configurations, use:

bash
git config --global --list

Example Output:

user.name=John Doe
user.email=john.doe@example.com
core.editor=code --wait
init.defaultbranch=main

To view a specific configuration value:

bash
git config --global user.name

Practical Applications​

Configuring Line Endings​

Line endings can cause issues when collaborating across different operating systems. Configure Git to handle line endings automatically:

For Windows users:

bash
git config --global core.autocrlf true

For macOS/Linux users:

bash
git config --global core.autocrlf input

Setting Up Aliases​

Git aliases allow you to create shortcuts for frequently used commands:

bash
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.unstage 'reset HEAD --'

After setting these aliases, you can use shortcuts like git co instead of git checkout.

Example usage:

Input:

bash
git st

Output: The same output as git status:

On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

Configuring Color Output​

Enable colored output in your terminal:

bash
git config --global color.ui true

Setting Default Pull Behavior​

Configure how Git handles merge conflicts during pulls:

bash
git config --global pull.rebase false  # merge (the default strategy)
# OR
git config --global pull.rebase true # rebase
# OR
git config --global pull.ff only # fast-forward only

Editing the Config File Directly​

Instead of using individual commands, you can edit the .gitconfig file directly:

bash
git config --global --edit

This will open your configured editor with the content of your global Git configuration file.

Example of a .gitconfig file:

[user]
name = John Doe
email = john.doe@example.com
[core]
editor = code --wait
autocrlf = input
[init]
defaultBranch = main
[alias]
co = checkout
br = branch
ci = commit
st = status
unstage = reset HEAD --
[color]
ui = true
[pull]
rebase = false

Advanced Configuration Options​

Configuring HTTP Proxy​

If you're working behind a proxy server:

bash
git config --global http.proxy http://proxyuser:proxypassword@proxyserver:port
git config --global https.proxy https://proxyuser:proxypassword@proxyserver:port

To remove the proxy settings:

bash
git config --global --unset http.proxy
git config --global --unset https.proxy

Setting Up Credential Storage​

To avoid typing your password repeatedly:

bash
# Store credentials in memory for 15 minutes
git config --global credential.helper cache

# Increase the timeout to 1 hour (3600 seconds)
git config --global credential.helper 'cache --timeout=3600'

# Store credentials permanently (use with caution)
git config --global credential.helper store

Common Issues and Solutions​

Resetting a Specific Configuration​

To remove a specific setting:

bash
git config --global --unset user.name

Resetting All Global Configurations​

To reset all your global configurations:

bash
rm ~/.gitconfig
# OR on Windows
del C:\Users\<username>\.gitconfig

Summary​

Global Git configuration provides a powerful way to customize your Git experience across all repositories on your system. By properly configuring settings like your identity, default editor, and common preferences, you can make Git more efficient and tailored to your workflow.

The most important global configurations to set up include:

  • Your user name and email
  • Your preferred text editor
  • Line ending preferences
  • Default branch name
  • Helpful aliases for common commands

Remember that global configurations can be overridden by local repository settings when needed, giving you flexibility while maintaining consistent defaults.

Additional Resources​

Exercises​

  1. Set up your global Git identity with your name and email.
  2. Create three useful Git aliases for commands you use frequently.
  3. Configure your preferred text editor for Git operations.
  4. View your current global Git configuration and identify any settings you might want to change.
  5. Try setting up different line ending configurations and observe how they affect a repository shared between different operating systems.


If you spot any mistakes on this website, please let me know at feedback@compilenrun.com. I’d greatly appreciate your feedback! :)