Skip to main content

Installing and Configuring Git

Now that you understand what version control systems are and why Git has become the industry standard, it's time to get Git running on your machine. In this lesson, you'll install Git and configure it with your personal information, setting the foundation for all your future Git operations.

Learning Goals

  • Install Git on Windows, macOS, or Linux
  • Configure your global Git settings
  • Verify your installation is working correctly
  • Understand basic Git configuration levels

Installing Git

The installation process varies by operating system. Choose the method that matches your environment.

Option 1: Git for Windows (Recommended) Download and run the installer from git-scm.com. This includes Git Bash, a terminal emulator that provides a Unix-like command line experience.

Option 2: Package Managers If you use Chocolatey:

Command Prompt as Administrator
choco install git

Or with Winget:

Command Prompt
winget install Git.Git

Verifying Your Installation

After installation, verify that Git is properly installed and check your version:

Terminal/Command Prompt
git --version

You should see output similar to:

git version 2.39.2
tip

If the command isn't recognized, you may need to restart your terminal or add Git to your system PATH. The Git for Windows installer typically handles this automatically if you choose the recommended settings.

Configuring Git

Before you start using Git, you need to configure your identity. Git uses this information to label every commit you make.

Setting Your Global Identity

Configure your name and email address (use your actual information):

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

Use an email address that matches your GitHub/GitLab account if you plan to use these services later. This ensures your commits are properly attributed to your account.

Checking Your Configuration

Verify your settings with:

Terminal
git config --list

Or check specific settings:

Terminal
git config user.name
git config user.email

Configuration Levels

Git supports multiple configuration levels. Here's how they work:

Setting different configuration levels
# System-level (affects all users on computer)
git config --system core.editor "code --wait"

# Global-level (affects all repositories for current user)
git config --global user.name "Your Name"

# Local-level (affects only current repository)
git config --local user.email "work.email@company.com"
note

Global configuration is stored in your home directory (~/.gitconfig on Unix systems, C:\Users\Username\.gitconfig on Windows). Local configuration is stored in each repository's .git/config file.

Common Configuration Options

Here are some useful configurations to enhance your Git experience:

Useful global configurations
# Set VS Code as default editor
git config --global core.editor "code --wait"

# Set default branch name to 'main'
git config --global init.defaultBranch main

# Enable colorful output
git config --global color.ui auto

# Create aliases for common 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

Testing Your Setup

Let's test that everything is working by creating a temporary repository:

Terminal
# Create a test directory
mkdir git-test
cd git-test

# Initialize a Git repository
git init

# Check that your configuration is being used
git config user.name
git config user.email

# Clean up
cd ..
rm -rf git-test

Common Pitfalls

  • Wrong email address: Using an email that doesn't match your GitHub account can lead to commits not being linked to your profile
  • Case sensitivity: On Windows, Git configuration is case-insensitive, but on Unix systems it's case-sensitive
  • Multiple configurations: Local configuration overrides global, which overrides system settings
  • Editor issues: If your default editor isn't configured properly, Git may hang when trying to open commit messages
  • PATH problems: After installation, you might need to restart your terminal or add Git to your system PATH manually

Summary

You've successfully installed Git and configured it with your personal information. You now have:

  • Git installed on your local machine
  • Your identity configured for commit attribution
  • Basic understanding of Git configuration levels
  • Some useful aliases and settings to improve your workflow

With Git properly set up, you're ready to create your first repository in the next lesson.

Git Configuration Basics – Quick Check

What command verifies that Git is properly installed?

Question 1/5