Ravindra BagaleCourses & study guides Track your progress

Guides

Git Basics for DevOps Beginners

Read this guide in: English · मराठी · हिंदी

Why do we need Git? Because there is a real problem between developers and operations when history is a zip. Developers change code on the laptop. Operations — the employee on the server side — copies “whatever build arrived last.” Friday night nobody knows which file is live. Git joins both sides: every save is a commit with who, when and why, then git push puts the same history on GitHub.

Friends, do not start with twenty Git commands. First understand the mystery-build fight. Then add, commit, push will feel natural.

Quick answer

Hold this vertical picture:

  1. Developer — edits code on the laptop.
  2. Operations — server-side employee who must put a known version on the server.
  3. The problem — WhatsApp/email zips; no author; “which build is live?”
  4. Git — commits replace mystery zips; push shares one history with the team.
  5. Pocket verbs: git add → git commit → git push.

Language: English · मराठी · हिंदी

Why do we need Git?

Developers and operations both care about the product, but without shared history they fight:

  1. Developers finish a change and say “done.”
  2. Operations on the server side needs a file they can trust — not three zips with different names.
  3. When production breaks, both need: who changed what, and when?

That is why beginners learn Git before pipelines.

What does operations have to do with Git?

  1. Operations is the server-side employee (or team).
  2. Their day includes deploy, restart, logs, rollback.
  3. Without Git they guess which zip to copy. With Git they deploy a known commit.

What is the problem? Suppose we are…

Suppose we are building Instagram (like updates)

Suppose your team ships Instagram-style profile badges.

  1. Monday — developer A emails profile-final.zip.
  2. Developer B also edits and WhatsApps profile-FINAL-v2.zip.
  3. Wednesday — operations (server-side) copies “the latest” by guesswork to production.
  4. Friday night — profile page wrong. “Worked on my laptop.” Nobody knows which zip is live.

Suppose we are working at Netflix and we are giving updates

Suppose Netflix pushes many small home-screen fixes a week. If history is only zip names in chat, operations cannot roll back to “Tuesday’s good build” with confidence.

Suppose you are working in Infosys on a client project

Suppose two Infosys developers email builds to the client operations team. Client asks: which attachment is approved? Without Git + review, release day is a war room.

Git: working tree, staging, commit history Edit files in the working tree, git add to stage, git commit to save a snapshot. Commits form history on the branch. Working tree edit files README.md add Staging git add index commit Repository (.git) git commit · snapshots c1 c2 c3 main → History answers: which build is live? (no mystery zip) status → add → commit Then git push shares the same history with the team / operations

Git path: edit in the working tree, git add to stage, git commit to save a snapshot on the branch history.

Git status, add, commit, log Terminal-style teaching diagram of git status, git add, git commit and git log --oneline.

Terminal-style teaching diagram: git status → git add → git commit → git log --oneline (lab-style output, not a live account).

How Git answers that same fight

  1. Verify Git: git --version (install from the official Git site if missing).
  2. Set identity once: git config --global user.name and user.email.
  3. mkdir myapp && cd myapp then git init — hidden .git is the history database.
  4. Write README.md → git add README.md → git commit -m "Add README".
  5. Empty GitHub repo → git remote add origin <URL> → git push -u origin main.

Now developers and the server-side person share one story.

Commands on the laptop

git --version
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
mkdir myapp && cd myapp
git init
git branch -M main
echo "# myapp" > README.md
git status
git add README.md
git commit -m "Add README"
git log --oneline
git remote add origin <REPO_URL>
git push -u origin main

Working tree = files on disk. Staging = what the next commit includes. Repository = saved commits. Read git status twice; commit once.

Ravindra Bagale's Tip

Students type git commit without git add and wonder why the change vanished — same chaos as emailing an empty zip to Infosys client ops. Before every commit: git status. Lakshat theva.

What you should see

  1. git log --oneline shows hash + message.
  2. After push, GitHub lists your files.
  3. Clean tree: git status says nothing to commit, working tree clean.

Common errors — story pain then fix

Pain from the stories Likely cause Fix
Please tell me who you are Name/email not set Set config before commit
nothing added to commit Forgot git add Stage, then commit
rejected on push Remote has commits you lack git pull --​rebase then push (when appropriate)
Wrong files in snapshot Staged too much Precise git add paths
Detached HEAD (later) Checked out a hash git checkout main

Everyday commands after the first save

git status
git diff
git diff --staged
git log --oneline -5
git restore FILE
git rm FILE

Samajla ka? Why Git = developer vs operations mystery-build fight; operations needs a known commit; Instagram / Netflix / Infosys “suppose” shows the mess; add → commit → push shares history. Five tiny commits tonight.

Frequently asked questions

What is Git?

Git is a version control system that stores snapshots (commits) of your project so you can track and undo changes.

What is a commit?

A commit is a saved snapshot with a message, author and unique hash.

What does git add do?

It stages chosen changes so the next commit includes only what you picked.

Do I need GitHub to use Git?

No. Git works locally. GitHub (or GitLab) is for remote hosting and teamwork.

What is the difference between Git and GitHub?

Git is the tool on your computer. GitHub is a website that hosts Git repositories.

Which branch name should beginners use?

Many new repos use main. Follow whatever your remote already uses.

Practice Tasks

About this scenario

Suppose we are on the DevOps team at IRCTC, the railway ticketing company, working from New Delhi. Suresh Yadav leads the team, and we look after the tatkal booking API. Costs are counted in INR. In the tasks below we do real DevOps jobs on this project using what this lesson teaches. IRCTC is a real company, but this project, the people, servers, IP addresses and numbers are made up for practice.

0 / 12

Easy Set your Git email

Why: GitHub links commits to your account using this email.

What to do: Set the global Git email to suresh@irctc.example.com.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Set your Git user name

Why: Every commit records who made it. A wrong name makes history confusing.

What to do: Set the Git user name to "Suresh Yadav" for all repositories on this laptop.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy List all files with details

Why: Hidden files (like .env) and file sizes or owners only show with the right options.

What to do: Show a long listing of every file, including hidden ones, in /var/www/irctc.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Click Check answer.

Easy Stage every change

Why: Before the first commit you usually want every new file included.

What to do: Stage every new and changed file in the current folder and below.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Stage one file

Why: Only staged changes go into the next commit.

What to do: Stage only the file Dockerfile for the next commit.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Clone a repository

Why: Cloning gives you the full project and its history on your machine.

What to do: Download the repository https://github.com/irctc/irctc-tatkal-booking.git to this machine.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Commit with a message

Why: A clear message tells the team why the change was made.

What to do: Commit the staged changes with the message "Add health check to tatkal-booking".

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Start a new Git repository

Why: Git can only track changes inside a folder that is a repository.

What to do: We are inside the new folder for the IRCTC tatkal booking API. Turn this folder into a Git repository.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Easy Create nested folders in one go

Why: Projects need a clean folder tree. Making all levels in one command saves time and avoids errors.

What to do: Create the folder /srv/irctc/reports/2026 for IRCTC. The parent folders do not exist yet, so create them too.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Click Check answer.

Easy Show where you are

Why: Before you copy or delete anything, you must know which folder you are in.

What to do: Suresh Yadav logged in to the IRCTC server and is not sure which folder the terminal is in. Print the current folder path.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Click Check answer.

Medium Stage tracked files and commit in one go

Why: For small fixes to tracked files, one command saves time.

What to do: Stage all already-tracked changed files and commit them with the message "Fix port 3000" in one command.

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.

Medium See staged changes

Why: Reviewing exactly what will be committed avoids surprises in review.

What to do: Show the line-by-line changes that are staged (not the unstaged ones).

How:
  1. Read the task and pick the tool it needs (git, docker, kubectl, terraform, ansible...).
  2. Write the tool name, then the sub-command (the action word).
  3. Add the flags the task needs, each followed by its value.
  4. Add names, files or paths at the end, then click Check answer.