Skip to main content

Command Palette

Search for a command to run...

πŸŽ‰ Day 13: Advanced Git & GitHub for DevOps Engineers πŸš€

Published
β€’5 min read
πŸŽ‰ Day 13: Advanced Git & GitHub for DevOps Engineers πŸš€
C

πŸ‘¨β€πŸ’» 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.

  1. Create a Branch: We’ll start by creating a branch called dev from the master branch. It’s like a new version of your code to work on.

     git checkout -b dev
    
  2. Add a Feature: Create a file called version01.txt inside the Devops/Git/ directory and add the following content:

     echo "This is the first feature of our application" > Devops/Git/version01.txt
    
  3. Commit 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"
    
  4. 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.

  1. 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"
    
  2. Add the Second Line (Oops, bad code):

     echo "This is gadbad code" >> Devops/Git/version01.txt
     git commit -am "Added buggy code"
    
  3. 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.

  1. Revert the Last Two Commits:

     git revert HEAD~2
    

    This 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.

  1. 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)

  2. Merge Changes into master: Once we’re done working in the dev branch, we can merge it back into the main branch.

     git checkout master
     git merge dev
    

    Now the master branch contains all your work! πŸŽ‰

  3. Rebase Example: Let’s practice rebasing. Move your dev branch commits on top of master:

     git rebase master
    

    This 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! πŸ’»πŸ”₯

More from this blog

C

chintamani's blogs

18 posts