Git Installation & Setup
Complete guide to installing Git and configuring your development environment
Git Installation & Setup
Git is a distributed version control system that tracks changes in your code, enables collaboration, and manages project history efficiently. This guide will walk you through installing Git and configuring it for optimal development workflow.
Prerequisites
Before installing Git, ensure you have:
- Administrative access on your computer
- Active internet connection for downloads
- A text editor (VS Code, Sublime Text, or similar)
Installation by Operating System
Windows Installation
Method 1: Official Installer (Recommended)
-
Download: Visit Git for Windows
-
Run Installer: Double-click the downloaded
.exe
file -
Configuration Options:
- ✅ Use recommended settings for most options
- ✅ Select "Git from the command line and also from 3rd-party software"
- ✅ Choose "Use the OpenSSL library" for HTTPS connections
- ✅ Configure line ending conversions: "Checkout Windows-style, commit Unix-style"
- ✅ Use Windows default console window
-
Verify Installation:
git --version
# Should output: git version 2.x.x.windows.x
Method 2: Using Package Managers
Using Chocolatey:
choco install git
Using Winget:
winget install --id Git.Git -e --source winget
macOS Installation
Method 1: Official Installer
- Download: Visit Git for macOS
- Install: Follow the installation prompts
- Verify:
git --version
Method 2: Using Homebrew (Recommended)
# Install Homebrew if you haven't already
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Git
brew install git
Method 3: Using Xcode Command Line Tools
xcode-select --install
Linux Installation
Debian/Ubuntu
# Update package list
sudo apt update
# Install Git
sudo apt install git
# Verify installation
git --version
CentOS/RHEL/Fedora
# For CentOS/RHEL
sudo yum install git
# For Fedora
sudo dnf install git
# Verify installation
git --version
Arch Linux
sudo pacman -S git
Essential Configuration
1. Set Your Identity
This is crucial - Git needs to know who you are for commit attribution:
# Set your name (use your real name)
git config --global user.name "Your Full Name"
# Set your email (use the same email as your GitHub account)
git config --global user.email "your.email@example.com"
2. Configure Default Branch Name
# Set default branch name to 'main' (modern standard)
git config --global init.defaultBranch main
3. Set Default Editor
# Use VS Code as default editor
git config --global core.editor "code --wait"
# Or use nano for simple editing
git config --global core.editor nano
# Or use vim (if you're comfortable with it)
git config --global core.editor vim
4. Configure Line Endings
# For Windows users
git config --global core.autocrlf true
# For macOS/Linux users
git config --global core.autocrlf input
5. Enable Color Output
git config --global color.ui auto
Advanced Configuration
Aliases for Common Commands
Set up shortcuts for frequently used commands:
# Status shortcut
git config --global alias.st status
# Checkout shortcut
git config --global alias.co checkout
# Branch shortcut
git config --global alias.br branch
# Commit shortcut
git config --global alias.ci commit
# Beautiful log display
git config --global alias.lg "log --oneline --graph --decorate --all"
# Show last commit
git config --global alias.last "log -1 HEAD"
# Unstage files
git config --global alias.unstage "reset HEAD --"
Configure Git to Handle Large Files
# Increase buffer size for large repositories
git config --global http.postBuffer 524288000
# Set pack window memory
git config --global pack.windowMemory "100m"
git config --global pack.packSizeLimit "100m"
Verification & Testing
Check Your Configuration
# View all global configurations
git config --global --list
# View specific configuration
git config --global user.name
git config --global user.email
Test Git Installation
- Create a test repository:
# Create and navigate to test directory
mkdir git-test && cd git-test
# Initialize repository
git init
# Create a test file
echo "# Git Test" > README.md
# Add and commit
git add README.md
git commit -m "Initial commit"
# Check log
git log --oneline
- Clean up:
cd .. && rm -rf git-test
SSH Key Setup (Recommended)
For secure authentication with GitHub:
Generate SSH Key
# Generate new SSH key (replace email with yours)
ssh-keygen -t ed25519 -C "your.email@example.com"
# Start SSH agent
eval "$(ssh-agent -s)"
# Add SSH key to agent
ssh-add ~/.ssh/id_ed25519
Add to GitHub
- Copy public key:
# On macOS
pbcopy < ~/.ssh/id_ed25519.pub
# On Linux
cat ~/.ssh/id_ed25519.pub
# On Windows
cat ~/.ssh/id_ed25519.pub | clip
- Go to GitHub → Settings → SSH and GPG keys → New SSH key
- Paste your key and save
Test SSH Connection
ssh -T git@github.com
Troubleshooting
Common Issues
"git is not recognized as a command" (Windows):
- Restart your terminal/command prompt
- Check if Git is in your PATH environment variable
- Reinstall Git with "Add Git to PATH" option checked
Permission denied (publickey) (SSH):
- Ensure SSH key is added to GitHub
- Check SSH agent is running:
ssh-add -l
- Verify SSH connection:
ssh -T git@github.com
Line ending issues:
- Configure
core.autocrlf
as shown above - Use
.gitattributes
file for repository-specific settings
Configuration Management
View Current Settings
# All configurations
git config --list
# Global configurations only
git config --global --list
# Local repository configurations
git config --local --list
Update Configuration
# Change user name
git config --global user.name "New Name"
# Change email
git config --global user.email "new.email@example.com"
Remove Configuration
# Remove specific setting
git config --global --unset user.name
git config --global --unset user.email
# Remove section
git config --global --remove-section user
Next Steps
✅ Congratulations! Git is now installed and configured on your system.
What's Next?
- Create your first repository - Learn repository fundamentals
- Clone existing projects - Work with remote repositories
- Master branching - Manage parallel development
Quick Verification Checklist
- Git version shows correctly (
git --version
) - User name is set (
git config user.name
) - User email is set (
git config user.email
) - Default branch is 'main' (
git config init.defaultBranch
) - SSH key is set up (optional but recommended)
- Test repository created and committed successfully