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
Linux
macOS

Windows Installation Methods

Method 1: Git for Windows (Recommended)

  1. Download from git-scm.com
  2. Run the installer (.exe file)
  3. Choose default options for most settings
  4. Important: Select "Git from the command line and also from 3rd-party software"
  5. Choose "Use the OpenSSL library"
  6. Select "Checkout Windows-style, commit Unix-style line endings"
  7. Use MinTTY (the default terminal for Git Bash)
  8. Complete installation
# Verify installation in Command Prompt or PowerShell
git --version
# Should display: git version 2.x.x.windows.1

Method 2: Chocolatey (Package Manager)

# Install Chocolatey first (if not installed)
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)

winget install --id Git.Git -e --source winget

Linux Installation (All Distributions)

Ubuntu/Debian

# Update package list
sudo apt update

# Install Git
sudo apt install git -y

# Verify installation
git --version

RHEL/CentOS/Fedora

# RHEL/CentOS 7+
sudo yum install git -y

# Fedora
sudo dnf install git -y

Arch Linux

sudo pacman -S git

Install from Source (Latest Version)

# Install dependencies
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)

# Install Homebrew if not installed
/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

xcode-select --install
# 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:

# Set your username (use your actual name for professional work)
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:

# Status aliases
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:

# Generate SSH key (use your email)
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

# Check Git version
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:

  1. System: /etc/gitconfig - All users on system
  2. Global: ~/.gitconfig - Your user account
  3. Local: .git/config - Specific repository
# Edit global config manually (VS Code example)
code ~/.gitconfig

# View config file locations
git config --list --show-origin

Frequently Asked Questions (FAQ)

Which Git version should I install?

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.

Should I use HTTPS or SSH with Git?

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

How do I update Git to the latest version?

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

What's the difference between global and local Git config?

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.

How do I fix "git is not recognized" error on Windows?

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

What are essential Git aliases for DevOps work?

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

How do I configure Git for multiple projects/companies?

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.

Previous: What is Git? Next: Basic Git Commands