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.
- Windows
- macOS
- Linux
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:
choco install git
Or with Winget:
winget install Git.Git
Option 1: Homebrew (Recommended)
brew install git
Option 2: Xcode Command Line Tools
xcode-select --install
Option 3: Direct Download Download the installer from git-scm.com.
Ubuntu/Debian:
sudo apt update
sudo apt install git
Fedora/RHEL:
sudo dnf install git
Arch Linux:
sudo pacman -S git
Verifying Your Installation
After installation, verify that Git is properly installed and check your version:
git --version
You should see output similar to:
git version 2.39.2
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):
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
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:
git config --list
Or check specific settings:
git config user.name
git config user.email
Configuration Levels
Git supports multiple configuration levels. Here's how they work:
# 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"
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:
# 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:
# 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?