Skip to main content

Command Palette

Search for a command to run...

Day 11 :Advance Git & GitHub for DevOps Engineers: Part-2

Day#11 Of 90 Days Of Devops Challenge

Published
7 min read
Day 11 :Advance Git & GitHub for DevOps Engineers: Part-2
V

Experienced QA professional with a passion for manual and automation testing. Proficient in DevOps practices, ensuring seamless integration and continuous delivery. Dedicated to ensuring top-notch software quality and efficiency. Eager to contribute my skills to Hashnode's vibrant tech community. Let's collaborate and create exceptional experiences!

👋Introduction

Hey there, fellow DevOps explorers!

If you're excited about diving into the DevOps world, you're in the right place. This article is like a treasure map leading you to some important secrets. We'll unravel the mysteries of Git Stash, master the skill of Cherry-Picking, unravel the puzzle of Git conflicts, and learn how to solve them without breaking a sweat. So, get ready, because we're about to embark on an awesome adventure!

🧲Git Stash: Saving Your Work in a Snap!

Picture this: you're in the middle of a project 🏗️, making all sorts of cool updates, and suddenly, boom! An urgent task comes up 🚨.

What about all those half-done changes you were excitedly working on?

Here comes Git Stash to the rescue! It's like a magical pocket where you can tuck away your changes ✨.

This lets you go back to a clean slate and switch to the urgent stuff without saying goodbye to your progress.

When you're ready to continue the fun, just unstash your changes 🎉, and you're back in action, right where you left off! 🚀

🍒Cherry-Pick - Why Do We Need It?

In DevOpsville, working together is super important 🤝. Imagine your pals tweak the code in their corner, and you spot some cool stuff you want in your spot. That's where Cherry-Picking hops in!

It's like plucking the yummiest cherries 🍒 from a tree. You get to pick special changes from one bunch and add them to yours.

This keeps your work tidy and snappy, without needing to mush all the branches together.

So, Cherry-Picking is like a magic wand for bringing the best changes to your code castle! 🏰✨

🤝Git Conflicts Unveiled: Why Do They Happen and How to Deal?

Let's have a friendly chat about Git conflicts – those tiny battles that happen when Git gets a bit puzzled while trying to mix changes.

Picture this: you and your pal tweak the same piece of code in different styles. Oopsie, now Git's scratching its digital noggin, trying to decide which version is the coolest. Surprise, it's conflict time! 🚨

These clashes can also pop up when you're blending branches that went on their adventures.

But guess what? Conflicts aren't the bad guys; they're the superheroes! 🦸‍♀️🦸‍♂️

They're like, "Hey, teamwork is in action!" So, don't sweat these little bumps, my friends, because they're a sign that you're brewing up some serious code magic together! 🎩🔮

🛠️Resolving Conflicts Like a Pro

Alright, let's talk about solving those tricky conflicts! Think of it as taming a wild puzzle. Git, our superhero, has a cool tool to help us sail through these stormy waters. When conflicts pop up, Git points out the problem spots in your files. Your mission: open those files, spot the clashes, and decide which changes to keep. Once you've chosen, save the file, lock in the changes, and you're back on track! And hey, teamwork is the secret sauce here – keep talking to your crew!

🌪️Making Conflict Resolution a Breeze

Here are some ninja moves to make conflict fixing super smooth:

  1. Frequent Pulls: Keep yanking updates from the main stash into your work area. This lowers the chance of big clashes.

  2. Crystal Clear Chats: Stay in sync with your team so everyone knows what's cookin'. This can stop conflicts from starting in the first place.

  3. Powerful Messages: Write smart notes about your changes. It's like leaving breadcrumbs for your team. This makes fixing clashes a walk in the park!

🌿Task 01-Git Branches and Stash - Your DevOps Power Moves!

Let's dive into Task 01 and get hands-on with Git's awesome tools. We'll use branches and a little stash magic to make your coding life smoother.

Here's how to do it:

Sure thing! Let's go through Task-01 using a command window:

Step 1: Create a New Branch and Make Changes

# Create a new branch and switch to it
git checkout -b new-feature

# Make your awesome changes here
# For example, edit some files or add new ones

Step 2: Stash Your Changes

# Stash your changes
git stash

Step 3: Switch, Commit, and Magic!

# Switch to a different branch, like "bug-fix"
git checkout bug-fix

# Make changes and commit them
# For example, fix a bug or add improvements
git add .
git commit -m "Fixed a bug"

Step 4: Bring Back the Magic

# Bring back your stashed changes and apply them on top of your new commits
git stash pop

That's it! You've completed Task-01 using Git commands 🪄👨‍💻

🌟Task-02: Enhancing Development Magic and Syncing with Production!

Task-02! We're going to level up our development branch and sync those commits with the mighty production branch.

Follow these steps :

Step 1: Add New Lines to version01.txt

Step 2: Commit the Changes

After bug fixing, this is the new feature with minor alteration”
This is the advancement of previous feature
Feature 2 is completed and ready for release
# Add the changes to the staging area
git add version01.txt

# Commit the changes with the first message
git commit -m "Added feature2.1 in development branch"

# Add Line3
# Commit with the second message
git commit -am "Added feature2.2 in development branch"

# Add Line4
# Commit with the third message
git commit -am "Feature2 completed"

Step 3: Sync with Production Branch (Rebase Time!)

# Switch to the production branch (replace 'production' with your actual branch name)
git checkout production

# Rebase to bring in the latest changes from the development branch
git rebase development

# Save and exit the editor if prompted

Step 4: Push to Remote

# Push the changes to your remote repository
git push origin production

There you have it! You've successfully enhanced your development branch and synchronized those commits with the production branch using the mighty rebase. 🚀👩‍💻

🍒Task-03: Cherry-Picking and Optimizing in Production!

In Task-03, we're going to cherry-pick a commit from the development branch into production and sprinkle some optimization magic.

Here's your step-by-step guide:

Step 1: Cherry-Pick "Added feature2.2 in development branch"

1.1 Switch to the production branch (if you're not already there):

1.2 Cherry-pick the commit "Added feature2.2 in development branch":

git checkout production
git cherry-pick <commit-hash>

Note: Replace <commit-hash> with the actual hash of the commit you want to cherry-pick, which you can find using git log

Step 2: Add New Lines for Optimization

2.1 Open version01.txt in your favorite text editor.

2.2 After the line "This is the advancement of previous feature", add the following lines:

Line4>> Added few more changes to make it more optimized.

Step 3: Commit the Optimization

# Add the changes to the staging area
git add version01.txt

# Commit the changes
git commit -m "Optimized the feature"

Step 4: Push to Remote

# Push the changes to your remote repository
git push origin production

You've successfully cherry-picked a commit into the production branch and optimized the feature. 🌟🍒

🎉Conclusion

Woohoo, amazing DevOps explorers! You've bravely set sail on this awesome adventure of learning. Git Stash, Cherry-Picking, and Conflict Resolution are super cool tools in your DevOps toolbox. They make working together super smooth, help keep your code in tip-top shape, and turn challenges into victories. And guess what? DevOps isn't only about code – it's all about teamwork, sharing ideas, and getting better every day.

Now armed with these newfound skills, charge ahead and make your mark in the thrilling universe of DevOps! Your coding journey is about to get even more exciting. Happy coding, and keep rocking it! 🚀👏

Happy git-ing!🚀🚀

Thank you for taking the time to read this blog. I hope you found the information helpful and insightful. So please keep yourself updated with my latest insights and articles on DevOps 🚀 by following me on :

Hashnode: vishaltoyou.hashcode.dev

LinkedIn: linkedin.com/in/vishalphadnis

So, Stay in the loop and stay ahead in the world of DevOps!

Happy learning 🚀😊🐧📦🔧🛠️💻💼🔍📈🚀🌟📊📚