Git & GitHub for DevOps and Cloud Engineers
Introduction to Git & GitHub
Git is a distributed version control system (DVCS) that helps developers and engineers track changes in their code, collaborate efficiently, and manage project history. GitHub is a cloud-based platform that hosts Git repositories, providing additional collaboration features like pull requests, issue tracking, and CI/CD integrations.
For DevOps and Cloud Engineers, mastering Git and GitHub is essential for:
Infrastructure as Code (IaC) (Terraform, Ansible, CloudFormation)
CI/CD Pipelines (Jenkins, GitHub Actions, GitLab CI)
Collaboration across development and operations teams
Version control for configuration files, scripts, and deployment manifests
Key Git Concepts
1. Version Control Basics
Repository (Repo): A project folder tracked by Git.
Commit: A snapshot of changes with a unique hash.
Branch: A parallel version of the code (e.g., main, dev, feature-branch).
Merge: Combining changes from different branches.
Pull Request (PR) / Merge Request (MR): A request to merge changes (used in GitHub/GitLab).
2. Essential Git Commands
# Initialize a new Git repo
git init
# Clone an existing repo
git clone <repo-url>
# Check status of changes
git status
# Stage changes for commit
git add <file> # or `git add .` for all files
# Commit changes with a message
git commit -m "Description of changes"
# Push changes to a remote repo (GitHub/GitLab)
git push origin <branch-name>
# Pull latest changes from remote
git pull origin <branch-name>
# Create & switch to a new branch
git checkout -b <branch-name>
# Merge a branch into current branch
git merge <branch-name>
GitHub for DevOps & Cloud Workflows
1. Collaboration Features
Pull Requests (PRs): Review and discuss code changes before merging.
Issues: Track bugs, enhancements, and tasks.
Projects: Kanban-style task management.
Actions: Automate CI/CD workflows (build, test, deploy).
2. Managing Infrastructure as Code (IaC)
Store Terraform, Ansible, Kubernetes manifests in GitHub.
Use branch protection rules to enforce code reviews.
Automate deployments using GitHub Actions.
3. CI/CD with GitHub Actions
Example workflow for deploying a cloud resource (AWS/Azure/GCP):
name: Deploy Terraform
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Terraform Apply
run: |
terraform init
terraform plan
terraform apply -auto-approve
Best Practices for DevOps Engineers
Branching Strategy: Use main for production, dev for staging, and feature branches.
Commit Messages: Follow a convention (e.g., feat:, fix:, chore:).
Git Ignore: Exclude unnecessary files (.terraform/, .env).
Security: Use GitHub Secrets for sensitive data (API keys, passwords).
Code Reviews: Enforce PR reviews before merging.