Installing and Configuring Git for DevOps
📌 DevOps Quick Start
Proper Git setup is the foundation of every DevOps workflow. This guide covers installation on all platforms and essential configuration for professional DevOps work.
Install Git on Your System
Choose your operating system below for installation instructions:
Windows Installation Methods
Method 1: Git for Windows (Recommended)
- Download from git-scm.com
- Run the installer (.exe file)
- Choose default options for most settings
- Important: Select "Git from the command line and also from 3rd-party software"
- Choose "Use the OpenSSL library"
- Select "Checkout Windows-style, commit Unix-style line endings"
- Use MinTTY (the default terminal for Git Bash)
- Complete installation
git --version
# Should display: git version 2.x.x.windows.1
Method 2: Chocolatey (Package Manager)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# Install Git using Chocolatey
choco install git -y
Method 3: Winget (Windows Package Manager)
Linux Installation (All Distributions)
Ubuntu/Debian
sudo apt update
# Install Git
sudo apt install git -y
# Verify installation
git --version
RHEL/CentOS/Fedora
sudo yum install git -y
# Fedora
sudo dnf install git -y
Arch Linux
Install from Source (Latest Version)
sudo apt install libz-dev libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext cmake gcc -y
# Download and compile
cd /tmp
wget https://github.com/git/git/archive/refs/tags/v2.40.0.tar.gz
tar -zxf v2.40.0.tar.gz
cd git-2.40.0
make prefix=/usr/local all
sudo make prefix=/usr/local install
macOS Installation Methods
Method 1: Homebrew (Recommended)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Git
brew install git
Method 2: Xcode Command Line Tools
# Then check if Git is installed
git --version
Method 3: Direct Download
Download from git-scm.com and follow the installer.
Essential Git Configuration for DevOps
After installing Git, configure it with your identity and preferences:
git config --global user.name "Your Name"
# Set your email (use your work email)
git config --global user.email "your.email@company.com"
# Set default branch name to main (industry standard)
git config --global init.defaultBranch main
# Set default editor (VS Code example)
git config --global core.editor "code --wait"
Recommended DevOps Git Configuration
| Setting | Command | Purpose |
|---|---|---|
| Color UI | git config --global color.ui auto |
Colorful output for better readability |
| Push Default | git config --global push.default simple |
Safer push behavior |
| Credential Helper | git config --global credential.helper store |
Store credentials (use cache for security) |
| Rebase on Pull | git config --global pull.rebase true |
Cleaner history when pulling |
| Prune on Fetch | git config --global fetch.prune true |
Clean up remote branches automatically |
Useful Git Aliases for DevOps Productivity
Aliases save time and reduce typing errors:
git config --global alias.st status
git config --global alias.stat "status -sb"
# Commit aliases
git config --global alias.ci commit
git config --global alias.cm "commit -m"
# Branch aliases
git config --global alias.br branch
git config --global alias.co checkout
# Log aliases (CRUCIAL for DevOps)
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.ll "log --oneline -10"
# DevOps specific aliases
git config --global alias.purge "!git branch --merged | grep -v '\\*\\|main\\|master' | xargs -n 1 git branch -d"
git config --global alias.wip "!git add . && git commit -m 'WIP'"
SSH Key Setup for Git (DevOps Essential)
SSH keys allow secure authentication without passwords:
ssh-keygen -t ed25519 -C "your.email@company.com"
# Press Enter for all defaults
# Start SSH agent
eval "$(ssh-agent -s)"
# Add SSH key to agent
ssh-add ~/.ssh/id_ed25519
# Display public key (add to GitHub/GitLab)
cat ~/.ssh/id_ed25519.pub
Verifying Your Git Setup
git --version
# View all configuration
git config --list
# Check specific setting
git config user.name
git config user.email
Quick Configuration File Reference
Git configuration is stored in three levels:
- System:
/etc/gitconfig- All users on system - Global:
~/.gitconfig- Your user account - Local:
.git/config- Specific repository
code ~/.gitconfig
# View config file locations
git config --list --show-origin
Frequently Asked Questions (FAQ)
Always install the latest stable version. For DevOps work, Git 2.30+ is recommended as it includes important security fixes and performance improvements. Check your current version with git --version.
SSH is preferred for DevOps:
• More secure with keys
• No password prompts
• Required for automation scripts
• Better for CI/CD pipelines
HTTPS is good for:
• Quick setup
• When behind restrictive firewalls
• Personal projects
Windows: Download and run the new installer from git-scm.com
Ubuntu/Debian: sudo apt update && sudo apt upgrade git
macOS (Homebrew): brew update && brew upgrade git
RHEL/CentOS: sudo yum update git
Global config (~/.gitconfig): Applies to all repositories for your user. Use for personal settings (name, email, aliases).
Local config (.git/config): Applies only to specific repository. Use for project-specific settings (remote URLs, branch policies).
System config (/etc/gitconfig): Applies to all users on the system. Usually set by system administrators.
This means Git is not in your PATH. Solutions:
1. Reinstall Git and select "Git from the command line and also from 3rd-party software"
2. Or add Git manually to PATH: C:\Program Files\Git\cmd
3. Use Git Bash instead of Command Prompt
4. Restart your terminal after installation
Must-have DevOps aliases:
• git config --global alias.lg "log --oneline --graph --decorate --all" - Visual history
• git config --global alias.co checkout - Quick checkout
• git config --global alias.st status - Quick status
• git config --global alias.purge "!git branch --merged | grep -v '\\*\\|main' | xargs -n 1 git branch -d" - Clean merged branches
• git config --global alias.wip "!git add . && git commit -m 'WIP'" - Quick work-in-progress commit
Use conditional includes in your global config:
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work
[includeIf "gitdir:~/personal/"]
path = ~/.gitconfig-personal
Then create separate config files with different user.name and user.email for each context.