🚀 Day 3: Git – Clone, Commit, Branch, Merge

Series: 30 Days DevOps Interview Preparation
Author: Tathagat Gaikwad
👋 Introduction
Welcome to Day 3 of the 30 Days of DevOps Interview Preparation!
Git is the industry-standard version control system that allows teams to collaborate, track changes, and manage code across multiple environments.
Whether you’re deploying infrastructure, managing CI/CD pipelines, or just writing scripts — Git is everywhere in DevOps.
🔍 What You’ll Learn Today
How to clone a repo from a remote source
How to commit your changes
How to create and work with branches
How to merge changes from one branch to another
🧠 1. git clone – Clone a Remote Repository
git clone
copies a repository from a remote source (e.g., GitHub, GitLab) to your local machine.
🧪 Example:
git clone https://github.com/tathagatgaikwad22/devops-interview-preparation.git
🔹 This command:
Initializes a new
.git
folderCopies all files, branches, and commit history
Sets the
origin
remote URL
✅ 2. git commit – Save Changes to Local Repo
Committing is saving a snapshot of your code.
Workflow:
git add . # Stage all changes
git commit -m "Fix: update login validation"
✅ Best Practices:
Use meaningful messages:
feat:
,fix:
,chore:
,docs:
Commit atomic changes — only one logical change per commit
🔎 View commit history:
git log --oneline
🌿 3. git branch – Parallel Development
Branches allow independent lines of development (e.g., features, bugfixes).
Common Branch Commands:
git branch # List all branches
git branch dev # Create branch
git checkout dev # Switch to branch
git checkout -b new-ui # Create & switch in one step
Always work in feature branches, not directly on
main
.
🔀 4. git merge – Combine Branches
Merging brings changes from one branch into another (usually main
or develop
).
Basic Merge:
git checkout main
git merge feature-xyz
✅ If both branches modified the same part of the same file, you’ll get a merge conflict.
Resolving Conflicts:
Open the file, fix the conflict manually
Stage the resolved file:
git add conflicted-file.txt
Commit the merge:
git commit
❓ Interview Questions & Detailed Answers
1️⃣ What’s the difference between git fetch
and git pull
?
git fetch
: Downloads changes from the remote but does not merge.git pull
: Fetches + automatically merges into your current branch.
🔎 Use fetch
when you want to review changes first before merging.
2️⃣ How do you resolve a merge conflict?
Git marks conflicting lines using:
<<<<<<< HEAD your changes ======= incoming changes >>>>>>> branch-name
Edit the file manually to keep the correct version.
Stage the file using
git add
, thengit commit
.
3️⃣ What is the purpose of branching in Git?
Branching allows developers to:
Work on features or fixes without affecting the main code
Collaborate without stepping on each other's toes
Isolate experiments and merge only after successful testing
4️⃣ What’s the difference between merge and rebase?
git merge
: Combines commits but retains history (creates a merge commit).git rebase
: Rewrites history by placing your changes on top of another branch.
⚠️ Use
rebase
carefully, especially on shared branches.
5️⃣ What’s your typical Git workflow for new features?
A standard Git flow looks like:
git checkout -b feature-xyz
# make changes
git add .
git commit -m "feat: added xyz"
git push origin feature-xyz
# Create a pull request (PR) and merge after review
🧪 Hands-on Practice Tasks
Clone a public GitHub repo
Create a feature branch, make a change, commit it
Merge the feature branch into main
Simulate a merge conflict by editing the same file on two branches
📌 Summary
Git is a non-negotiable skill for every DevOps engineer. If you can manage branches, commit cleanly, and resolve conflicts confidently—you’re already ahead in most interviews.
#Git #VersionControl #DevOps #DevOpsInterviewPrep #GitClone #GitCommit #GitBranch #GitMerge #30DaysOfDevOps #CloudEngineering #GitHub #OpenSource #CareerGrowth #HashnodeDevOps
Subscribe to my newsletter
Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
