π Day 13: Advanced Git & GitHub for DevOps Engineers π

π¨βπ» Chintamani Tare | DevOps Enthusiast & Linux Advocate π I'm a passionate DevOps engineer with a solid foundation in Linux system administration. With a deep interest in automation, cloud technologies, and CI/CD pipelines, I love simplifying complex tasks and building scalable infrastructure. Whether it's scripting in Bash, managing servers with Ansible, or deploying applications with Docker and Kubernetes, I'm always eager to explore the latest tools and practices in the DevOps space.
Welcome to Day 13 of your journey into the world of Git! Today, we're diving into some really cool concepts like Git Branching, Revert & Reset, and the hot debate of Rebase vs Merge! This is where you go from being a Git user to a Git master! π Let's break it all down with simple, exciting steps.
πΏ Git Branching: Your Playground for Development πΏ
Branches in Git are like parallel universes for your project. You can create a new branch to work on a feature or fix a bug without messing with the main codebase. Once you're done, you can merge that branch back into the main branch.
Why branches?
You can work on new features independently. π
Fix bugs without breaking the main code. π
Experiment with new ideas in a sandbox. π§ͺ
For example, in a big project, you could have a branch for Feature A, a branch for Feature B, and the main branch (master or main). Each one operates independently, so you're never stepping on anyoneβs toes.
π₯ Git Revert vs Reset: Fixing Oops Moments π₯
Sometimes, things go wrong. π¬ Maybe you added the wrong code, or something just didnβt work. No worries! Git has your back with Revert and Reset. Letβs see what they do:
Git Reset: It's like a time machine! β³ It rewinds your project to an earlier point and erases the changes you made after that. But beware: this can permanently delete history if you're not careful! π§
Git Revert: This is the safer option. Instead of deleting commits, it creates a new commit that undoes the changes. It's like making a correction in your timeline without removing history. Perfect when youβre collaborating! π
βοΈ Git Rebase vs Git Merge: The Battle of History βοΈ
Alright, here comes the epic showdown! Git Rebase and Git Merge are two ways to combine branches, but they do it very differently. Which one should you use? π€
π οΈ Git Merge:
Think of merge as bringing two branches together while keeping the full history intact.
Youβll see every commit from both branches when you look back.
Itβs a bit messy, but you donβt lose any details! Ideal for keeping all contributions visible. π
β¨ Git Rebase:
Rebase is like tidying up history. It moves commits from one branch to another, making it look like everything happened in one clean line.
History gets rewritten, making it look super neat. Perfect for when you want a clean, linear history. π§Ό
β οΈ Warning: Be cautious with rebase when working with a shared repository! It rewrites history, which can cause confusion for other developers if used incorrectly.
π§ Hands-On: Letβs Practice! π οΈ
Letβs get into the real action with some tasks! Ready? Here we go!
Task 1: Feature Development with Branches π
Letβs create a new feature in a separate branch without touching the main branch.
Create a Branch: Weβll start by creating a branch called
devfrom themasterbranch. Itβs like a new version of your code to work on.git checkout -b devAdd a Feature: Create a file called
version01.txtinside theDevops/Git/directory and add the following content:echo "This is the first feature of our application" > Devops/Git/version01.txtCommit the Feature: You need to commit this new feature with a clear message:
git add Devops/Git/version01.txt git commit -m "Added new feature"Push it to GitHub: Finally, send your branch up to GitHub so others can see it:
git push origin dev
π Woohoo! You just created and pushed your first feature branch! Great job!
Task 2: Add More Features with Separate Commits βοΈ
Now letβs update our file, and weβll commit the changes after each update.
Add the First Line:
echo "This is the bug fix in development branch" >> Devops/Git/version01.txt git commit -am "Added bug fix in development branch"Add the Second Line (Oops, bad code):
echo "This is gadbad code" >> Devops/Git/version01.txt git commit -am "Added buggy code"Add the Third Line (More bad code):
echo "This feature will gadbad everything from now" >> Devops/Git/version01.txt git commit -am "Added more buggy code"
Step 3: Revert to a Previous Version π
Uh-oh! We made some mistakes with that bad code. π Letβs revert to the commit where everything was still working fine.
Revert the Last Two Commits:
git revert HEAD~2This will undo the last two buggy changes, leaving only the good code. Youβre back to a clean state! π§Ό
Task 3: Working with Branches πΏ
Letβs create and merge multiple branches.
Create Two More Branches: Letβs add more branches to simulate a bigger project:
git branch feature1 git branch feature2 git branch(Join screenshot here to show branch structure)
Merge Changes into
master: Once weβre done working in thedevbranch, we can merge it back into the main branch.git checkout master git merge devNow the
masterbranch contains all your work! πRebase Example: Letβs practice rebasing. Move your
devbranch commits on top ofmaster:git rebase masterThis creates a linear history, making everything look cleaner and more organized! π§Ή
π Wrapping It Up π
Today, youβve learned some powerful Git techniques. From creating branches for safe development, to using revert and reset to fix mistakes, and understanding the difference between merge and rebase, youβve leveled up your Git game! πͺ
The more you practice, the more comfortable youβll get. Git is one of the most essential tools for every DevOps engineer, and mastering it will make you a rockstar in your team! π
Letβs keep pushing code and building amazing things! π»π₯



