← Back to tools

Foundations

Git & GitHub Documentation

Git and GitHub manage source code and collaboration workflows.

Level: Beginner

What Is Git & GitHub?

Git & GitHub is a beginner-level DevOps tool used to manage specific parts of software delivery and operations. It helps teams standardize workflows and reduce manual effort.

Why We Use It

Teams use Git & GitHub to improve speed, reliability, and consistency. It reduces repetitive manual work, lowers failure risk, and makes collaboration easier across development and operations.

Where It Fits In DevOps

It sits at the base of every DevOps workflow. Without this layer, CI/CD, cloud, and reliability work become slow and error-prone.

From Beginner To End-to-End

1. Foundations

Start with core Git & GitHub concepts and basic setup so you can use it safely in day-to-day work.

- Understand Git & GitHub fundamentals

- Set up local/dev environment

- Run first working example

2. Team Workflow

Integrate Git & GitHub into real team practices with repeatable conventions and collaboration patterns.

- Adopt standards and naming conventions

- Integrate with repositories and CI/CD

- Create reusable templates

3. Production Operations

Use Git & GitHub in production with observability, security, and rollback plans.

- Monitor behavior and failures

- Secure access and secrets

- Define incident and rollback flow

4. Scale and Optimization

Continuously improve reliability, performance, and cost while standardizing usage across services.

- Improve performance and cost

- Automate compliance checks

- Document best practices for the team

Key Concepts

- Commits

- Branches

- Pull requests

Learning Path

- Basic git flow

- Branching strategy

- Code review process

Real Use Cases

- Local and remote server operations

- Code collaboration workflows

- Task automation in build and deploy scripts

Beginner Learning Plan

- Read the Git & GitHub basics and terminology

- Run at least one hands-on mini project

- Break and fix a small setup to build confidence

- Document your first repeatable workflow

Advanced / Production Plan

- Integrate Git & GitHub with your full delivery pipeline

- Add security and policy checks

- Add observability and incident playbooks

- Define reusable standards for multiple services

Common Mistakes

- Using defaults in production without security hardening

- Skipping monitoring and post-deployment validation

- No rollback strategy for failed changes

- Over-complex setup before mastering fundamentals

Production Readiness Checklist

- Access control and least privilege applied

- Secrets managed securely

- Monitoring and alerting enabled

- Rollback and recovery process tested

- Documentation updated for team onboarding

Installation Guide

Install Git & GitHub on host with practical commands and verification steps.

Install Git (Ubuntu/Debian)

sudo apt update && sudo apt install -y git

Configure identity

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Verify install

git --version

Quick Start

Initialize repository

git init

Add and commit changes

git add . && git commit -m 'init'

Push to remote

git push origin main

Common Commands

Simple command list with short descriptions.

git status

Show changed files and branch status.

git diff

See unstaged changes.

git diff --staged

See staged changes.

git add .

Stage all changed files.

git add -p

Stage changes interactively (best practice).

git commit -m "msg"

Create a commit from staged changes.

git commit --amend

Edit last commit (before pushing).

git log --oneline --decorate --graph -n 20

Readable recent history.

git show <sha>

Inspect a commit.

git branch -vv

Show local branches and upstream tracking.

git checkout -b feature/x

Create and switch to a new branch.

git switch -c feature/x

Modern alternative to checkout (create branch).

git switch -

Toggle to previous branch.

git fetch --all --prune

Update refs and delete removed remote branches.

git pull --rebase

Update branch with a clean history.

git push -u origin HEAD

Push current branch and set upstream.

git push --force-with-lease

Safer force push (protects others’ work).

git stash push -m "wip"

Temporarily save changes.

git stash pop

Re-apply stashed changes.

git rebase -i HEAD~3

Interactive rebase to squash/clean commits.

git reset --soft HEAD~1

Undo last commit but keep changes staged.

git reset --hard HEAD

Discard local changes (danger).

git revert <sha>

Create a new commit that undoes a commit (safe for shared branches).

git tag -a v1.0.0 -m "release"

Create an annotated tag.

git push origin --tags

Push tags to remote.

Reference

Official documentation:

https://git-scm.com/doc

Complete Guide

A full, structured guide for this tool (with commands, diagrams, best practices, and learning path).

Git & GitHub

A complete DevOpsLabX guide for Git & GitHub: what it is, why we use it, key concepts, commands, best practices, and how to learn it.

At A Glance

  • Category: Foundations
  • Difficulty: Beginner
  • Outcome: learn the fundamentals, then build real workflows, then make it production-ready

Prerequisites

  • Basic computer usage and curiosity to work in the terminal
  • Willingness to practice daily commands and read logs

Glossary

  • Commit: A snapshot of changes saved to your repo history.
  • Branch: A line of development for changes (feature, fix, etc.).
  • Pull Request (PR): A request to merge changes with review.
  • Rebase: Rewrite commit history to a cleaner linear sequence.
  • Merge: Combine changes from branches.

Overview

Git and GitHub manage source code and collaboration workflows.

Architecture Diagram

A real, visual mental model of how Git & GitHub fits into a typical workflow.

Git Architecture

WorkspaceStagingLocal RepositoryRemote Repositorygit add / mv / rmgit commitgit commit -agit reset <file>git reset <commit>git pushgit fetchgit clone / pullgit diffgit diff HEAD

Think in four areas: working directory, staging index, local repo history, and remote repo.

Reference Architecture (Production)

A production-oriented view: guardrails, checks, and the parts that matter when it breaks.

Production Reference Flow

TerminalcommandsOSservicesFiles/etc /varProcessesps/topNetworkdns/portsGit & GitHubrepeatable operations

This diagram is a practical mental model, not vendor-specific.

Key Concepts

  • Commits
  • Branches
  • Pull requests

Concept Deep Dive

Commits

Commits is a core idea you’ll use repeatedly while working with Git & GitHub.

Why it matters: Understanding Commits helps you design safer workflows and troubleshoot issues faster.

Practice:

  • Explain Commits in your own words (1 minute rule).
  • Find where Commits appears in real docs/configs for Git & GitHub.
  • Create a small example that uses Commits, then break it and fix it.

Branches

Branches is a core idea you’ll use repeatedly while working with Git & GitHub.

Why it matters: Understanding Branches helps you design safer workflows and troubleshoot issues faster.

Practice:

  • Explain Branches in your own words (1 minute rule).
  • Find where Branches appears in real docs/configs for Git & GitHub.
  • Create a small example that uses Branches, then break it and fix it.

Pull requests

Pull requests is a core idea you’ll use repeatedly while working with Git & GitHub.

Why it matters: Understanding Pull requests helps you design safer workflows and troubleshoot issues faster.

Practice:

  • Explain Pull requests in your own words (1 minute rule).
  • Find where Pull requests appears in real docs/configs for Git & GitHub.
  • Create a small example that uses Pull requests, then break it and fix it.

Core Workflow

1. Foundations

Start with core Git & GitHub concepts and basic setup so you can use it safely in day-to-day work.

Goals:

  • Understand Git & GitHub fundamentals
  • Set up local/dev environment
  • Run first working example

2. Team Workflow

Integrate Git & GitHub into real team practices with repeatable conventions and collaboration patterns.

Goals:

  • Adopt standards and naming conventions
  • Integrate with repositories and CI/CD
  • Create reusable templates

3. Production Operations

Use Git & GitHub in production with observability, security, and rollback plans.

Goals:

  • Monitor behavior and failures
  • Secure access and secrets
  • Define incident and rollback flow

4. Scale and Optimization

Continuously improve reliability, performance, and cost while standardizing usage across services.

Goals:

  • Improve performance and cost
  • Automate compliance checks
  • Document best practices for the team

Quick Start

  1. Initialize repository
git init
  1. Add and commit changes
git add . && git commit -m 'init'
  1. Push to remote
git push origin main

Tutorial Series

A tutorial-style sequence (like a handbook). Do these in order to build skill from beginner to production.

Tutorial 1: Git & GitHub Setup and Verification

Goal: Get a working environment and confirm basic commands run.

Steps:

  1. Verify you understand what the tool does and what problem it solves.
  2. Install or enable it on your machine (or in a sandbox environment).
  3. Run the smallest working example and write down what happened.
  4. Create a dedicated lab folder to avoid breaking real files.
mkdir -p ~/devopslabx-labs && cd ~/devopslabx-labs
  1. Practice safe inspection commands (do not modify configs yet).
pwd && ls -la && whoami && id

Checkpoints:

  • You can run commands without copy/paste errors
  • You know where your files are and how to navigate

Exercises:

  • Create a notes file of 15 commands you used today
  • Explain your terminal workflow in 5 sentences

Goal: Become fast at finding and understanding information on a system.

Steps:

  1. Create a sample file and practice searching and filtering.
printf "alpha\nbeta\ngamma\n" > sample.txt
  1. Search for a string and show line numbers.
grep -n "beta" sample.txt
  1. Combine commands using pipes.
ps aux | head

Checkpoints:

  • You can use pipes confidently
  • You can find a value in a file quickly

Exercises:

  • Find where a service stores logs on your machine
  • Find all files modified in the last 24 hours in a folder

Tutorial 3: Permissions and Process Basics

Goal: Understand the most common production errors: permissions and processes.

Steps:

  1. Inspect permissions.
ls -l
  1. Make a script executable and run it.
printf '#!/usr/bin/env bash\necho ok\n' > run.sh && chmod +x run.sh && ./run.sh
  1. Find and stop a process safely (TERM before KILL).
sleep 9999 & echo $!

Checkpoints:

  • You understand r/w/x and user/group/other
  • You can stop a runaway process

Exercises:

  • Trigger a permission denied error and fix it without using chmod 777
  • Write down the difference between TERM and KILL

Command Cheatsheet

  • git status: Show changed files and branch status.
  • git diff: See unstaged changes.
  • git diff --staged: See staged changes.
  • git add .: Stage all changed files.
  • git add -p: Stage changes interactively (best practice).
  • git commit -m "msg": Create a commit from staged changes.
  • git commit --amend: Edit last commit (before pushing).
  • git log --oneline --decorate --graph -n 20: Readable recent history.
  • git show <sha>: Inspect a commit.
  • git branch -vv: Show local branches and upstream tracking.
  • git checkout -b feature/x: Create and switch to a new branch.
  • git switch -c feature/x: Modern alternative to checkout (create branch).
  • git switch -: Toggle to previous branch.
  • git fetch --all --prune: Update refs and delete removed remote branches.
  • git pull --rebase: Update branch with a clean history.
  • git push -u origin HEAD: Push current branch and set upstream.
  • git push --force-with-lease: Safer force push (protects others’ work).
  • git stash push -m "wip": Temporarily save changes.
  • git stash pop: Re-apply stashed changes.
  • git rebase -i HEAD~3: Interactive rebase to squash/clean commits.
  • git reset --soft HEAD~1: Undo last commit but keep changes staged.
  • git reset --hard HEAD: Discard local changes (danger).
  • git revert <sha>: Create a new commit that undoes a commit (safe for shared branches).
  • git tag -a v1.0.0 -m "release": Create an annotated tag.
  • git push origin --tags: Push tags to remote.

Learning Path

  • Basic git flow
  • Branching strategy
  • Code review process

Beginner To Advanced Path

Beginner Path (Foundations)

What to learn:

  • Learn Git & GitHub terminology and the “why” behind it
  • Install/setup and run a first working example
  • Understand the main components and the default workflow
  • Learn safe debugging: where to look when something fails
  • Build a small checklist for your own repeatable setup
  • Write notes (commands, errors, fixes) while learning

Hands-on labs:

  • Follow a hello-world style tutorial and document every step
  • Break one config intentionally and fix it (learn error patterns)
  • Write a 10-command cheat sheet you can reuse later
  • Create a simple diagram of the tool’s flow in your own words

Milestones:

  • You can explain the tool in 2 minutes
  • You can reproduce a working setup from scratch
  • You can troubleshoot the top 3 common failures
  • You can share a clean quick-start with someone else

Intermediate Path (Real Workflows)

What to learn:

  • Use the tool inside a realistic DevOps workflow
  • Create reusable templates/configs and standard naming conventions
  • Add security basics: secrets handling and least privilege
  • Reduce toil: automate repeated steps and build confidence
  • Make the workflow faster and safer (cache, validations, checks)
  • Document the workflow as if onboarding a new teammate

Hands-on labs:

  • Integrate it with a CI pipeline (lint/build/test/deploy style flow)
  • Parameterize config for dev/stage/prod environments
  • Create a runbook: steps to validate and roll back a change
  • Add a preflight validation step that blocks unsafe changes

Milestones:

  • You can onboard another person with your docs
  • You can run the tool consistently across environments
  • You can explain tradeoffs (speed vs safety, flexibility vs complexity)
  • You can debug failures using logs/outputs without guesswork

Advanced Path (Production & Scale)

What to learn:

  • Operate the tool safely in production with guardrails
  • Add observability: metrics/logs/traces and meaningful alerts
  • Optimize performance/cost and standardize across multiple services
  • Design failure modes and recovery (rollback, restore, incident flow)
  • Create upgrade strategy and test it (versioning, compatibility)
  • Create ownership: docs, alerts, dashboards, and operational SLAs

Hands-on labs:

  • Add policy checks (security scans, approvals, protected environments)
  • Load test or scale test the workflow and measure bottlenecks
  • Create an incident simulation and write a postmortem template
  • Automate audits: drift checks, compliance checks, and reports

Milestones:

  • You can detect failures quickly and recover safely
  • You can maintain the setup long-term (upgrade strategy, docs, ownership)
  • You can explain architecture decisions and alternatives
  • You can standardize patterns across multiple services/teams

Hands-On Labs

Beginner Labs

  • Install/setup and verify version
  • Run the smallest working example
  • Change one parameter and observe the behavior
  • Cause a safe failure and document the fix

Intermediate Labs

  • Integrate into a realistic workflow (pipeline, deploy, or automation)
  • Parameterize configuration for two environments
  • Add validation and rollback steps
  • Write a runbook (steps + commands) for common failures

Advanced Labs

  • Add guardrails (policy checks, approvals, least privilege)
  • Add observability and meaningful alerts
  • Load/scale test and identify bottlenecks
  • Create an upgrade + rollback plan and test it

Advanced Topics

  • Version pinning and upgrade strategy
  • Standardization across teams (templates, docs, reviews)
  • Integration patterns with Git & GitHub in real systems
  • Observability and auditing around usage
  • Performance tuning and reliability guardrails

Production Patterns

  • Documented standards and onboarding
  • Backups for critical data/config
  • Monitoring/alerting for failures
  • Access control and auditability for Git & GitHub
  • Regular upgrade plan and change log review

Real-World Scenarios

  • A production service is failing: use Git & GitHub to inspect logs, processes, disk, and networking.
  • A deployment failed: verify permissions, file paths, environment variables, and service status.
  • Automate repetitive operations with scripts and validated checklists.

Troubleshooting

  • Reproduce the issue with the smallest possible example
  • Check logs/output first, then configuration, then permissions/credentials
  • Validate inputs (versions, environment variables, file paths, network access)
  • Rollback to last known-good state if production is affected
  • Write down the root cause and add a guardrail so it does not repeat

Runbook Templates

Use these templates to make your docs feel like real production documentation.

Deploy Runbook

  • Purpose
  • Preconditions (secrets, access, approvals)
  • Steps to deploy (exact commands)
  • Post-deploy verification (health checks)
  • Rollback steps
  • Owner and escalation

Incident Triage Runbook

  • Impact assessment (who is impacted?)
  • Current signals (errors, latency, saturation)
  • Recent changes (deploys, config, infra)
  • First checks (logs, health endpoints, dependencies)
  • Mitigation steps (rate limiting, rollback, scale)
  • Follow-up actions (postmortem, guardrails)

Checklist (Copy/Paste)

  • What changed since it last worked?
  • What do logs say at the exact failure time?
  • Is the service reachable on the expected port and DNS?
  • Are credentials/permissions valid?
  • Is disk full, memory exhausted, or CPU pegged?
  • Do we have a safe rollback plan and is it tested?

Security & Best Practices

  • Never hardcode secrets in code or commits
  • Use least privilege (roles, scopes, minimal permissions)
  • Prefer reproducible builds/configs over manual steps
  • Add validations before applying changes (lint/validate/plan/dry-run)
  • Keep documentation and runbooks updated
  • Version pin critical dependencies and plan upgrades

Common Error Patterns

Symptom

You don’t know where to start

Likely cause: Trying advanced setups before fundamentals

Fix steps:

  • Finish one working quick start
  • Write a cheat sheet and a runbook
  • Only then add production guardrails

FAQ

What is Git & GitHub used for?

Git & GitHub is used to standardize and automate parts of delivery and operations so teams can ship faster and more reliably.

How long does it take to learn Git & GitHub?

You can get productive in days with fundamentals, but production mastery comes from building workflows, debugging failures, and operating it over time.

What should I learn before Git & GitHub?

Learn basic Linux + Git first, then follow the prerequisites section. Fundamentals make every advanced topic easier.

How do I use Git & GitHub safely in production?

Add guardrails: least privilege, validation before apply/deploy, monitoring, and a tested rollback plan.

Common Mistakes

  • Using defaults in production without security hardening
  • Skipping monitoring and post-deployment validation
  • No rollback strategy for failed changes
  • Over-complex setup before mastering fundamentals

Production Readiness Checklist

  • Access control and least privilege applied
  • Secrets managed securely
  • Monitoring and alerting enabled
  • Rollback and recovery process tested
  • Documentation updated for team onboarding

Mini Projects

  • Build a small project that uses Git & GitHub in a realistic workflow
  • Write a checklist for production usage
  • Create a troubleshooting runbook for common failures
  • Create a one-page internal doc: setup, usage, debugging, rollback

Interview Questions

  • Explain what Git & GitHub is and where it fits in DevOps.
  • Describe a real problem you solved using Git & GitHub.
  • What can go wrong in production, and how do you detect and recover?
  • What are the most common mistakes beginners make with this tool?
  • How do you document and standardize usage across a team?
  • How do you plan upgrades and compatibility changes?

References

Extended Documentation

Extra long-form notes for Git & GitHub. This loads on demand so the page stays fast.