Git - Installation & Setup
Before you can use Git, you need to install it and configure it with your identity. This guide covers installation on all major operating systems and essential configuration.
Installing Git
Windows Installation
Method 1: Git for Windows (Recommended)
- Download from https://git-scm.com/download/win
- Run the installer with these recommended settings:
- ✅ Use Git from the command line and also from 3rd-party software
- ✅ Use the OpenSSL library
- ✅ Checkout Windows-style, commit Unix-style line endings
- ✅ Use MinTTY (the default terminal of MSYS2)
- This installs Git Bash, Git GUI, and command line tools
Method 2: Chocolatey Package Manager
# In PowerShell (as Administrator)
choco install git
Method 3: Winget (Windows 10+)
# In PowerShell
winget install Git.Git
macOS Installation
Method 1: Homebrew (Recommended)
# Install Homebrew first: https://brew.sh
brew install git
Method 2: Xcode Command Line Tools
# This installs an older version but works
xcode-select --install
Method 3: Official Installer
- Download from https://git-scm.com/download/mac
- Run the .pkg installer
Linux Installation
Ubuntu/Debian:
sudo apt update
sudo apt install git
CentOS/RHEL/Fedora:
# CentOS/RHEL
sudo yum install git
# Fedora
sudo dnf install git
Arch Linux:
sudo pacman -S git
Verifying Installation
After installation, verify Git is working:
git --version
git version 2.42.0
Essential Configuration
Git needs to know who you are for commit attribution. This information goes into every commit you make:
Setting Your Identity
# Replace with your actual name and email
git config --global user.name "John Doe"
git config --global user.email "[email protected]"
Choosing Your Default Editor
Git will open an editor for commit messages. Choose one you're comfortable with:
git config --global core.editor "code --wait"
# Vim (advanced users)
git config --global core.editor "vim"
# Nano (simple terminal editor)
git config --global core.editor "nano"
# Notepad++ (Windows)
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
# Sublime Text
git config --global core.editor "subl --wait"
Setting Default Branch Name
git config --global init.defaultBranch main
Line Ending Configuration
git config --global core.autocrlf true
git config --global core.autocrlf input
Viewing Your Configuration
git config --list
git config user.name
git config user.email
John Doe
[email protected]
Configuration Levels
Git has three configuration levels:
- --system: Applies to all users on the system
- --global: Applies to all repositories for your user
- --local: Applies only to the current repository
# Global (most common)
git config --global user.name "John Doe"
# Local (repository-specific)
git config --local user.email "[email protected]"
# View configuration locations
git config --list --show-origin
Setting Up SSH Keys (Recommended)
SSH keys provide secure, passwordless authentication with Git hosting services:
Generate SSH Key
# Generate new SSH key (replace email with yours)
ssh-keygen -t ed25519 -C "[email protected]"
Enter file in which to save the key (/Users/john/.ssh/id_ed25519): [Press Enter]
Enter passphrase (empty for no passphrase): [Type passphrase or Press Enter]
Enter same passphrase again: [Repeat passphrase or Press Enter]
Add SSH Key to SSH Agent
# Start ssh-agent
eval "$(ssh-agent -s)"
# Add key to agent
ssh-add ~/.ssh/id_ed25519
# Start ssh-agent
eval $(ssh-agent -s)
# Add key to agent
ssh-add ~/.ssh/id_ed25519
Copy Public Key
# macOS
cat ~/.ssh/id_ed25519.pub | pbcopy
# Linux
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard
# Windows Git Bash
cat ~/.ssh/id_ed25519.pub | clip
# Or just display it
cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILmBzgmvDdOyWvN4/1Y6Tr4UbCzSIk9GlXeE2U3+a1b2 [email protected]
Add to GitHub/GitLab
GitHub:
- Go to Settings → SSH and GPG keys
- Click "New SSH key"
- Paste your public key
- Give it a descriptive title
Test SSH connection:
ssh -T [email protected]
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Useful Aliases
Set up shortcuts for common commands:
# Essential aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
git config --global alias.lg "log --oneline --graph --decorate --all"
Now you can use short commands:
git st # instead of git status
git co main # instead of git checkout main
git lg # beautiful log graph
Additional Helpful Settings
# Show more context in diffs
git config --global diff.context 5
# Use better diff algorithm
git config --global diff.algorithm histogram
# Automatically rebase when pulling
git config --global pull.rebase true
# Push only current branch by default
git config --global push.default simple
# Colorful output
git config --global color.ui auto
Troubleshooting Installation
Command Not Found
- Windows: Restart terminal, check PATH in Environment Variables
- macOS: May need to run
xcode-select --install
- Linux: Ensure package installation completed successfully
Permission Issues
# Fix SSH key permissions (Unix-like systems)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
Verification Checklist
Confirm your setup is complete:
- ✅
git --version
shows version number - ✅
git config user.name
shows your name - ✅
git config user.email
shows your email - ✅
git config core.editor
shows your preferred editor - ✅ SSH key is generated and added to hosting service
- ✅
ssh -T [email protected]
authenticates successfully
Next Steps
Great! Git is now installed and configured. Let's create your first repository and learn the basic workflow: