Git & GitHub Playbook For DevOps & Azure Engineers
Git & GitHub Playbook For DevOps & Azure Engineers
Strong Foundation
What is Git?
Every small change matters — you can't afford chaos. Git acts like a time machine and a
collaboration manager for your project’s source code.
Git is a distributed version control system (VCS) that allows developers to track changes,
collaborate effectively, and revert mistakes if necessary.
In DevOps, speed and stability are non-negotiable. Git helps teams work in parallel, experiment
safely, and merge code seamlessly — forming the backbone of modern Continuous Integration and
Continuous Deployment (CI/CD) pipelines.
Without Git, coordinating software development would feel like juggling with re — one wrong
move, and you risk burning down months of work!
• Git is the tool you use locally. It's the engine that tracks changes to your les.
• GitHub is the service where you can host your Git repositories online.
Think of Git as your personal diary where you write daily notes, and GitHub as a library where
you can publish your diary so others can collaborate, review, or contribute.
In DevOps, using a remote hosting service like GitHub, GitLab, Bitbucket, or Azure Repos is
crucial because it enables centralized collaboration, backup, code reviews, and triggering
automated pipelines based on Git events.
fi
fi
Install Git and Basic Con guration
Setting up Git is like moving into a new house — a little setup makes everything smoother later.
1. Install Git:
◦ Windows: Download from git-scm.com and install.
These commands personalize your commits with your identity — so your team knows who made
what changes.
You can also con gure other settings like default editors or merge tools later.
• Staging Area (Index): A place where you prepare speci c changes before making them
of cial.
• Repository (Commit History): Where your nalized snapshots are stored permanently.
• You make changes ➔ stage changes ➔ commit them ➔ push to remote (like GitHub).
This clear separation prevents mistakes — you can pick and choose what to commit, and avoid
accidentally sending un nished work!
fi
fi
fl
fi
fi
fi
fi
fi
fi
How to Initialize a Git Repository
Every journey begins with a single step — in Git, it’s:
git init
This simple command creates a hidden .git folder in your project directory, which holds all the
magic — the entire version control system.
From this moment, Git starts watching every move you make.
git status
• Which les are untracked (new les Git doesn’t know about yet)
Think of git add as selecting clothes before packing — you’re deciding what should be
included in your next travel bag (commit).
fi
fi
fi
fi
Committing Changes with a Message
Once you're happy with what you've staged, you can record a permanent snapshot with:
The message is crucial — it’s the story behind that change. A good commit message is clear,
concise, and describes what and why, not just how.
E.g.,
git log
(Each commit is shown in one simple line — great for quick glances.)
git diff
• View staged changes (already added but not yet committed):
and reset HEAD as "Oops! I added the wrong le; let me just remove it from packing
without losing it."
fi
fi
fi
Intermediate Git Concepts – Taking Control of
Collaboration & Code Flow
This command downloads the entire repository, including all les, branches, and history, into
your local system.
It's like photocopying an entire book so you can read and contribute to it without touching the
original.
From now on, your local copy is connected to the remote one — so you can pull updates or push
your changes.
If you initialized a project locally and later decide to push it to GitHub, connect it with:
• You can verify with git remote -v to see all connected remotes.
You’re saying: “Hey GitHub, here’s my work – add it to the main branch!”
You’ll use this every time you want to upload your local changes.
You're saying: “Bring in updates from the remote main branch and merge them into mine.”
Great for keeping in sync with teammates — but it merges right away.
This silently grabs the latest changes from remote — but doesn’t touch your current les.
Use it when you want to check what's new before deciding to merge.
Create a Branch
Now you’re ready to code without worrying about breaking the main project.
Behind the scenes, Git compares changes between both branches and tries to automatically
combine them.
This gives a visual of how branches split and merged — super helpful for debugging or team
discussions.
<<<<<<< HEAD
your change
=======
someone else's change
>>>>>>> feature-xyz
fl
fi
fl
You need to edit the le manually, decide which change (or both) to keep, and then:
In DevOps, this is common during hot xes, release merges, or CI/CD pipeline deployments with
multiple contributors.
Deleting Branches
Once a branch has done its job, clean up to avoid clutter:
This tells the remote (e.g., GitHub): “Remove this branch from your side too.”
This cleanup is crucial in professional work ows to keep repositories organized and CI/CD
pipelines manageable.
fi
fi
fl
Important GIT Commands
git stash
Example:
You’re working on a hot x, but suddenly need to switch branches to address a critical issue. Just
stash your current changes, switch, and come back later.
git stash pop – “Apply your last stashed changes back to your working
directory.”
Syntax:
Example:
After xing the production bug, you return to your original task. Use git stash pop to
recover where you left off — like pulling saved edits from a drawer.
git rebase – “Reapply commits from your branch onto another base commit,
rewriting history.”
Syntax:
Example:
You want your feature branch to have a clean, linear history on top of main, so you rebase it to
make the commit tree look like a straight timeline.
fi
fi
git cherry-pick – “Selectively apply a speci c commit from another
branch.”
Syntax:
Example:
You xed a critical bug on a test branch and want that x in main without merging the entire
branch — cherry-pick that golden commit like picking a single cherry from a tree.
Example:
Before deploying to production, tag the release commit as v1.0.0 — making it easier to track
and rollback if needed.
git clean – “Remove untracked les and directories from your working
directory.”
Syntax:
Example:
After testing scripts or temporary builds, use git clean -fd to sweep away all untracked les
— like cleaning your desk before the next task.
git revert – “Create a new commit that undoes the effect of a previous
commit (safe undo).”
Syntax:
You committed a con g that breaks staging. Use revert to undo it without changing history,
keeping the team’s timeline intact.
git reset --hard – “Dangerously reset your repo and wipe out
uncommitted changes — use with caution!”
Syntax:
Example:
You went down a wrong path and want to completely reset to a clean state — reset --hard is
like pressing “nuclear undo” (but be sure you really want it).
git pull – “Fetch and merge remote changes into your current branch in one
step.”
Syntax:
Example:
You're on the develop branch and want the latest updates from the remote.
Run:
This is like syncing your local notebook with the shared team version — everyone gets on the same
page instantly.
Syntax:
You want to see what changes are available on the remote main branch without affecting your
local copy. Run:
Now, you can review them using git log origin/main — think of it like syncing emails
without reading them yet.
git merge – “Integrate another branch’s changes into your current branch.”
Syntax:
Example:
Run:
It’s like combining two Google Docs into one — the current one gets the new updates added in.
• git pull: Combines fetch + merge in one go. It downloads and merges remote changes
into your current branch immediately.
• git fetch + git merge: Fetch grabs changes without applying them. You get a
chance to review before merging manually.
GitHub Basics – Your Developer Passport to
Collaboration
In today’s world of software development,
GitHub is not just a code-hosting platform — it's the collaborative hub where code meets
conversation, creativity meets control, and DevOps pipelines begin to ow.
If Git is your version control engine, GitHub is the vehicle that takes it global. Here's your
comprehensive, real-world guide to mastering GitHub for DevOps and development teams.
Every GitHub journey begins with a repository — the place where your project lives, grows, and
evolves.
• Public Repos: Great for open-source work, community collaboration, or sharing learning
projects. Anyone can see it.
• Private Repos: Ideal for enterprise apps, pre-release projects, or con dential code. Access is
restricted.
Example: Creating a private repo for your new CI/CD pipeline scripts to share only with your
DevOps team.
Once your repository is set up, pushing your local code to GitHub is as easy as:
Every push is like publishing your latest chapter to a shared team book. GitHub helps track what
changed, when, and by whom — no more emailing zip les!
fi
fi
fl
Understanding GitHub UI – Navigate Like a Pro
GitHub’s interface is not just intuitive — it’s built for collaboration, review, and visibility.
Files Tab
Commits Tab
Want to know who xed the production bug last night at 2AM? This is where you look.
Branches Tab
Feature A in one branch, Feature B in another — all safely isolated and parallel.
See ongoing and past PRs, team discussions, approvals, and reviews.
This is where collaboration really happens — it’s like a code negotiation table.
Use it to:
“Here’s what I built. Can we review and merge it into the main project?”
• Comments inline
It’s the DevOps equivalent of Change Advisory Board (CAB) meetings, but lightweight and
developer-friendly.
• Enforce standards
Approve
Comment
Request changes
Example:
• Bugs
• Enhancements
• Discussions
Example: Raise an issue titled “CI job fails on PR merge” and assign it to the pipeline engineer
with a label: ci/CD.
Every repo comes with a Wiki — a space for documentation, FAQs, SOPs, or even onboarding
notes.
Example:
Document your team's Terraform module standards or Git work ow right inside the repo — no
need for Google Docs scattered across drives.
• To Do
• In Progress
• In Review
• Done
Example:
Use GitHub Projects to manage sprint stories for your microservices refactor — all visible in one
dashboard.
fl
GitHub Advanced – Supercharging DevOps
with Enterprise-Grade Git Work ows
Branch protection rules allow you to control how changes enter critical branches like main or
production.
Example:
In an Azure-based microservices project, protect your release branch to allow merges only
after two team leads review the PR and all Azure DevOps pipelines pass.
It’s like placing a security gate before production — no more rogue code sneaking in.
GitHub Actions is a game-changer — it allows you to automate build, test, and deploy work ows
with just a few lines of YAML.
name: CI Pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: echo "Hello from GitHub Actions!”
Want to deploy a Docker container to Azure Web App? Here's what a real-world work ow might
include:
• Checkout code
Example: Use GitHub Actions to auto-deploy your React frontend to Azure Static Web Apps
whenever a PR is merged to main.
Tip: You can trigger different jobs based on le changes, branches, or even commit messages.
Store API keys, Azure tokens, passwords, or Docker credentials in GitHub Secrets — and use them
safely in your work ows.
env:
AZURE_TOKEN: ${{ secrets.AZURE_TOKEN }}
Example:
Save your Azure service principal credentials in GitHub Secrets to authenticate deployments
securely from Actions.
Never hard-code secrets. Think of GitHub Secrets as the vault that locks your automation down.
Example: Schedule a nightly backup job that runs at midnight UTC using:
on:
schedule:
- cron: '0 0 * * *'
Webhooks allow GitHub to send HTTP payloads to other services when speci c events occur.
GitHub Packages allows you to store and manage Docker images, npm packages, Maven
artifacts, and more, right alongside your code.
Example:
Build a Docker image in GitHub Actions and push it to GitHub Packages. Use it later in Kubernetes
deployments from a trusted source.
Example:
Best Practice:
Use GitHub Teams and Repo Roles to enforce least-privilege access — especially for production-
facing pipelines.
And when GitHub’s developer- rst work ow meets Azure DevOps’ enterprise-grade CI/CD —
it unlocks seamless automation, faster delivery, and infrastructure you can trust at scale.
Let’s dive deep into how GitHub and Azure work better together to deploy apps, containers, and
infrastructure with con dence.
fi
fi
fl
Connect Azure Pipelines with GitHub Repo – CI/CD Begins at
GitHub, Deploys via Azure
You can connect any GitHub repository to Azure Pipelines in a few clicks, allowing Azure
DevOps to monitor branches and automate builds and releases.
Steps:
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo "Building from GitHub source!”
Use Case:
Auto-trigger CI pipeline every time a developer pushes code to main, and run tests or Docker
builds before deployment.
Think of GitHub as your source-of-truth and Azure Pipelines as your orchestration powerhouse.
How it Works:
steps:
- checkout: git://GitHubRepo@main
This helps teams gradually move to GitHub or mix repositories without disrupting CI/CD ows.
Real-world case:
Teams keeping IaC code in GitHub and application code in Azure Repos — both orchestrated from
Azure Pipelines.
• GitHub Actions builds & deploys to Azure Web App via azure/webapps-
deploy@v2
- uses: azure/webapps-deploy@v2
with:
app-name: 'shruthi-web'
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
package: .
Azure VMs
• Use Azure CLI or SSH inside GitHub Actions to deploy artifacts or containers
fi
fl
Bonus: Enable deployment slots, app settings, or VM scripts as part of the work ow — your infra
is now programmable.
- uses: hashicorp/setup-terraform@v2
- run: terraform init
- run: terraform plan
- run: terraform apply -auto-approve
Authenticate via Azure CLI or service principal (store credentials in GitHub Secrets)
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- run: az deployment group create \
--resource-group rg-name \
--template-file main.bicep
Real-World Flow:
Work ow:
3. Push to GitHub:
git push origin feature/add-user-auth
Real-World Example:
• Once completed and tested in Dev, it gets merged back into develop and promoted to
higher environments.
Best For: Teams practicing continuous integration with multiple developers working in parallel.
fl
fl
fl
fi
2. Git ow Work ow — Structured Release Management
Purpose: A proven branching strategy for stable releases, especially in enterprise environments
with complex deployments.
Main Branches:
Example Flow:
# Prepare release
# Release to production
Hot x
Process:
Example:
Paired with automated GitHub Actions or Azure Pipelines to run unit tests and deploy code to
staging instantly.
Best For: Startups, microservice teams, or modern SaaS apps using CI/CD- rst strategies.
Deployment Flow:
5. git merge qa
Each merge triggers CI/CD via GitHub Actions or Azure Pipelines → deploys to correct Azure
environment.
Best For: DevOps teams automating multi-environment deployments (App Services, AKS,
Functions, VMs).
Pros:
Cons:
/services
/auth
/payment
/notification
fl
/common
Pros:
• Simpli ed tooling
Cons:
Real-World Decision:
• Polyrepo is great for teams with clear ownership and fast-moving services.
• Monorepo shines when services are tightly coupled or share core libraries, and you want
centralized control.
Basic Git commands get you started — but these advanced tools elevate your work ow into
enterprise-grade DevOps maturity.
Let’s unpack some game-changing features every DevOps engineer, SRE, or cloud-native
developer must know.
A submodule lets you embed a separate Git repository inside another repo as a dependency —
without copying code manually.
fi
fl
Think of it like:
You’re building multiple microservices that share a common logging library. Instead of duplicating
it, you add it as a submodule:
Bonus: Each submodule tracks its own history and updates independently.
Submodules require extra care during cloning (git clone --recursive) and CI/CD. Use
them when code reuse across teams is essential.
git worktree allows you to check out multiple branches simultaneously in different folders
— without constantly switching back and forth.
You’re xing a production bug in main while also developing a new feature in develop.
• repo/ on develop
• main-worktree/ on main
Use worktrees when juggling hot xes, releases, and features in parallel — without losing your
local context.
fi
fi
3. GitHub Enterprise vs Free GitHub — Scaling securely
GitHub Free:
GitHub Enterprise:
• Tailored for large organizations, regulated industries, and advanced DevOps automation.
• Key features:
If your organization needs compliance (SOC2, HIPAA, ISO), or you're managing 100+ engineers
across multiple teams — GitHub Enterprise gives control, visibility, and security.
You can launch a fully con gured VS Code editor in the browser with your repo pre-cloned and dev
containers pre-con gured.
You onboard a new DevOps engineer. Instead of telling them to set up Docker, Terraform CLI,
node, and Python...
.devcontainer/devcontainer.json
A proactive, code- rst security suite integrated right into your repo:
Features:
1. Code Scanning
◦ Automatically scans code for vulnerabilities (uses CodeQL).
2. Secret Scanning
◦ Finds accidentally committed secrets (e.g., AWS keys, Slack tokens).
3. Dependency Review
◦ Flags vulnerable packages in PRs.
◦ GitHub blocks it
◦ Sends an alert
Combine GitHub Actions with Advanced Security to automate secure CI/CD pipelines that
catch issues before code hits production.
fi