What is Git? Version Control Basics for DevOps

📌 DevOps Quick Take

Git is a distributed version control system that tracks changes in source code. Every DevOps engineer MUST know Git - it's the foundation of CI/CD, collaboration, and deployment automation.

What is Git in Simple Terms?

Git is a tool that helps developers track changes in their code. Think of it as a "time machine" for your codebase - you can go back to any point in time, see what changed, and work with others without overwriting each other's work.

Why Git Matters for DevOps

  • CI/CD Foundation: Every modern CI/CD pipeline starts with Git
  • Infrastructure as Code (IaC): Terraform, Ansible, Dockerfiles - all versioned in Git
  • Collaboration: Multiple DevOps engineers can work on the same project
  • Rollback Ability: Quickly revert to working versions if deployment fails
  • Audit Trail: See who changed what and when

Centralized vs Distributed Version Control

Aspect Centralized (SVN, CVS) Distributed (Git)
Repository Single central server Every user has full copy
Internet Required Yes, for most operations No, work offline
Speed Slower (network dependent) Faster (local operations)
Branching Complex and slow Simple and fast
DevOps Use Limited in modern pipelines Standard for all CI/CD

Git Architecture - The 3 Areas

1. Working Directory

Where you actually make changes to files. This is your local workspace.

2. Staging Area (Index)

A "preview" area where you prepare changes before committing. This is unique to Git.

3. Repository (.git folder)

Where Git stores all commits and history. This is what gets cloned/copied.

# Basic Git workflow example
git init # Initialize repository
git add . # Stage all changes
git commit -m "message" # Save changes with message
git push origin main # Send to remote repository

Key Git Concepts DevOps Engineers Should Know

Repository (Repo)

A project folder that Git tracks. Contains all files and version history.

Commit

A snapshot of your code at a specific point in time. Each commit has a unique ID (SHA-1 hash).

Branch

A separate line of development. Main/master is production, feature branches are for development.

Merge

Combining changes from different branches. Essential for GitFlow workflows.

Remote

A shared repository (GitHub, GitLab, Bitbucket) where teams collaborate.

DevOps Workflow with Git

  1. Clone repository to local machine
  2. Create branch for feature/fix
  3. Make changes to code/configuration
  4. Test locally before committing
  5. Commit changes with descriptive messages
  6. Push to remote and create Pull Request
  7. CI/CD pipeline automatically runs tests
  8. Merge to main after approval
  9. Auto-deploy to staging/production

💡 DevOps Pro Tip

Always use meaningful commit messages! Follow the convention: type(scope): description. Example: feat(kubernetes): add deployment yaml for app or fix(ci): resolve docker build failure.

Git in the DevOps Toolchain

  • Infrastructure: Terraform/CloudFormation files in Git
  • Configuration: Ansible/Chef/Puppet scripts versioned
  • Containers: Dockerfiles and docker-compose.yml
  • Kubernetes: YAML manifests for deployments
  • CI/CD: Jenkinsfile, .gitlab-ci.yml, GitHub Actions
  • Documentation: README.md, runbooks, procedures

Essential Git Commands for DevOps

# Initialize & Clone
git init
git clone https://github.com/user/repo.git

# Basic Workflow
git status
git add filename
git commit -m "message"
git push

# Branching (CRUCIAL for DevOps)
git branch
git checkout -b feature-branch
git merge branch-name

# Remote Operations
git pull
git fetch
git remote -v

Common DevOps Git Patterns

GitFlow

Structured branching model with develop, feature, release, hotfix, and main branches.

GitHub Flow

Simpler: main branch always deployable, feature branches, PRs, merge to deploy.

Trunk-Based Development

Short-lived feature branches, frequent merges to main. Great for CI/CD.

Quick Start for DevOps Engineers

1. Install Git on your system
2. Set your username and email: git config --global user.name "Your Name"
3. Clone a repo: git clone repo-url
4. Make changes and commit: git add . && git commit -m "changes"
5. That's it! You're using Git.

Interview Focus Points

  • Explain Git in 2 minutes
  • Difference between Git and GitHub
  • What is a merge conflict and how to resolve it?
  • Explain git rebase vs merge
  • How Git enables CI/CD pipelines
  • What is .gitignore and why is it important?
Back to Git Mastery Next: Installing Git