Installing and Configuring Git
Now that you understand what Git is and why it's important, it's time to get Git installed on your computer and configure it properly. In this lesson, we'll cover installation for all major operating systems and essential configuration settings.
Installing Git
Windows Installation
There are several ways to install Git on Windows:
Method 1: Git for Windows (Recommended)
1. Visit: https://git-scm.com/download/win
2. Download the latest version (64-bit recommended)
3. Run the installer
4. Recommended settings during installation:
• Use default text editor (Vim or VS Code)
• Let Git decide (default branch name: main)
• Git from command line and 3rd-party software
• Use bundled OpenSSH
• Use OpenSSL library
• Checkout Windows-style, commit Unix-style line endings
• Use MinTTY terminal
• Default (fast-forward or merge)
• Git Credential Manager
• Enable file system caching
5. Click "Install" and wait for completion
Method 2: GitHub Desktop (GUI + Git)
1. Visit: https://desktop.github.com
2. Download and install GitHub Desktop
3. Git is included automatically
macOS Installation
Method 1: Homebrew (Recommended)
Open Terminal and run:
brew install git
Method 2: Xcode Command Line Tools
Open Terminal and run:
xcode-select --install
This installs Git along with other development tools.
Method 3: Official Installer
1. Visit: https://git-scm.com/download/mac
2. Download the .dmg file
3. Open and follow installation instructions
Linux Installation
Debian/Ubuntu:
sudo apt update
sudo apt install git
Fedora:
sudo dnf install git
Arch Linux:
sudo pacman -S git
CentOS/RHEL:
sudo yum install git
Tip: On Linux, you can also build Git from source for the absolute latest version, but the package manager version is usually sufficient and easier to maintain.
Verifying Git Installation
After installation, verify that Git is properly installed:
# Check Git version
git --version
Expected output:
git version 2.43.0 (or higher)
# Check Git help
git --help
This displays available Git commands and options.
Important: If you get "command not found" or similar error, you may need to restart your terminal or command prompt, or check your system PATH variable.
Initial Git Configuration
Before you start using Git, you need to configure your identity. Every Git commit uses this information, and it's immutably baked into the commits you create.
Setting Your Name and Email
# Set your name (required)
git config --global user.name "Your Name"
# Set your email (required)
git config --global user.email "your.email@example.com"
Example:
git config --global user.name "John Doe"
git config --global user.email "john.doe@gmail.com"
Important: Use the same email address you'll use for GitHub/GitLab accounts to properly link your commits to your profile.
Understanding Configuration Levels
Git has three levels of configuration, each overriding the previous:
1. System Level (--system)
Location: /etc/gitconfig (Linux/Mac) or C:\ProgramData\Git\config (Windows)
Applies to: Every user on the system and all repositories
Usage: Rarely used, requires admin privileges
git config --system user.name "System Name"
2. Global Level (--global)
Location: ~/.gitconfig or ~/.config/git/config
Applies to: Current user, all repositories
Usage: Most common, your personal settings
git config --global user.name "Your Name"
3. Local Level (--local or no flag)
Location: .git/config (inside repository)
Applies to: Only the current repository
Usage: Project-specific settings
git config --local user.name "Project Specific Name"
Priority Order (highest to lowest):
Local (--local) > Global (--global) > System (--system)
This means local settings override global, which override system.
Essential Configuration Settings
Default Text Editor
# Set VS Code as default editor
git config --global core.editor "code --wait"
# Set Sublime Text as default editor
git config --global core.editor "subl -n -w"
# Set Nano as default editor (simple, terminal-based)
git config --global core.editor "nano"
# Set Vim as default editor (Git default)
git config --global core.editor "vim"
# Set Notepad++ (Windows)
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Default Branch Name
# Set default branch name to "main" (modern convention)
git config --global init.defaultBranch main
Previously, the default was "master", but "main" is now standard.
Configuring Line Endings
Different operating systems use different line ending characters, which can cause issues in cross-platform collaboration:
Windows:
# Checkout Windows-style (CRLF), commit Unix-style (LF)
git config --global core.autocrlf true
macOS/Linux:
# Checkout as-is (LF), commit Unix-style (LF)
git config --global core.autocrlf input
Understanding Line Endings:
• Windows uses CRLF (Carriage Return + Line Feed: \r\n)
• Unix/Mac uses LF (Line Feed: \n)
• Git handles conversion automatically with autocrlf
Important: Proper line ending configuration prevents "phantom" changes where Git shows every line as modified when nothing actually changed.
Color Output
# Enable colored output (usually enabled by default)
git config --global color.ui auto
This makes Git output easier to read with color-coded information.
Credential Helper
Windows:
git config --global credential.helper manager
macOS:
git config --global credential.helper osxkeychain
Linux:
git config --global credential.helper cache
This stores your credentials so you don't have to enter them repeatedly.
Viewing Your Configuration
# View all configuration settings
git config --list
# View all settings with their file locations
git config --list --show-origin
# View specific setting
git config user.name
git config user.email
# View global settings only
git config --global --list
# View local settings only
git config --local --list
Editing Configuration Files
# Open global config in default editor
git config --global --edit
# Open local config in default editor (run inside a repository)
git config --local --edit
# Open system config in default editor (requires admin)
git config --system --edit
Useful Additional Configurations
# Set default pull behavior (merge or rebase)
git config --global pull.rebase false
# Enable helpful command suggestions
git config --global help.autocorrect 10
# Set default diff tool
git config --global diff.tool vimdiff
# Set default merge tool
git config --global merge.tool vimdiff
# Ignore file permissions (useful for cross-platform work)
git config --global core.fileMode false
# Show original branch name in conflict markers
git config --global merge.conflictstyle diff3
Recommendation: Start with the essential settings (name, email, editor, default branch, line endings) and add more configurations as you become comfortable with Git.
Removing Configuration Settings
# Remove a specific setting
git config --global --unset user.name
# Remove a section
git config --global --remove-section user
Complete Initial Setup Example
Here's a complete initial setup for a new Git installation:
# Essential identity settings
git config --global user.name "John Doe"
git config --global user.email "john.doe@gmail.com"
# Default branch name
git config --global init.defaultBranch main
# Line endings (choose based on your OS)
git config --global core.autocrlf true # Windows
# OR
git config --global core.autocrlf input # macOS/Linux
# Default editor (choose your preferred editor)
git config --global core.editor "code --wait"
# Color output
git config --global color.ui auto
# Pull behavior
git config --global pull.rebase false
# Verify settings
git config --list
Troubleshooting Common Issues
Issue: Git command not found
Solution:
1. Restart terminal/command prompt
2. Check PATH variable includes Git
3. Reinstall Git with proper PATH option
Issue: Wrong email in commits
Solution:
git config --global user.email "correct@email.com"
(Note: Only affects future commits)
Issue: Permission denied (Windows)
Solution:
Run Command Prompt or PowerShell as Administrator
Issue: Unable to edit config
Solution:
Manually edit config file:
Windows: C:\Users\YourName\.gitconfig
Mac/Linux: ~/.gitconfig
Hands-On Exercise:
Complete these configuration tasks:
- Verify Git is installed by checking the version
- Configure your name and email globally
- Set your default branch name to "main"
- Configure line endings for your operating system
- Set your preferred text editor
- View all your Git configuration settings
Commands:
git --version
git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main
git config --global core.autocrlf true # or input
git config --global core.editor "code --wait"
git config --list
Summary
In this lesson, you learned:
- How to install Git on Windows, macOS, and Linux
- How to verify Git installation with git --version
- The three configuration levels: system, global, and local
- Essential configuration: name, email, editor, branch name, line endings
- How to view and edit configuration settings
- Credential helpers for storing authentication
- Common configuration troubleshooting
Next Up: In the next lesson, we'll dive deep into Git's architecture to understand how Git stores and manages your data!