Day-11: Advance Git & GitHub for DevOps Engineers: Part-2
Day-11 of 90 Days of DevOps Challenge
Introduction🎉
Hello there, DevOps enthusiasts! Today, we embark on an exciting journey to unravel some mysterious concepts in Git. Don't worry; I'll be your friendly guide, and together, we'll make these seemingly tough ideas as easy as a Sunday morning. So buckle up, and let's get started!
Concepts💭
Cherry-Pick🍒 - The Git Wizardry of Selective Commits
Picture this: you're working on a project, and suddenly you spot a commit made by a teammate that seems like magic—just what you need! Well, you're in luck because Git has a spell called "cherry-pick" that can make that commit yours!
Cherry-picking allows you to pluck a specific commit from one branch and add it to another. Imagine it as carefully picking the juiciest cherries from a tree and enjoying them without having to take the whole branch.
Now, let's sprinkle some command magic to make it happen:
git cherry-pick <commit-hash>
Just replace <commit-hash>
with the unique identifier of the commit, you wish to pick. Git will work its magic and apply that commit to your current branch. Voila! 🌟
Stash🚬 - The Hidden Treasure of Temporary Storage
Here's a common scenario: you're working on a feature branch, and suddenly, an urgent bug fix request comes in. You need to switch to another branch quickly, but you don't want to commit your half-baked changes. What do you do? Stash them away!
Think of "stash" as a magical container that lets you store your unfinished work safely until you're ready to continue.
Here's how you conjure the stash:
git stash save "description of your stash"
The "description of your stash" is like a label for your stash, helping you remember what you stashed later on. To retrieve your hidden treasure, use:
git stash apply
Or if you want to remove it from the stash after applying, use:
git stash pop
Now you can seamlessly switch branches and later return to your stash, like finding a forgotten treasure map leading you back to your work. Argh! 🏴☠️
Resolving Merge Conflicts⚔ - The Heroic Quest to Unity
Imagine this epic tale: you and your teammate have been working hard on different branches. When it's time to merge your work, Git faces a dilemma—conflicting changes! Fear not, for you are the hero who can resolve this conflict and bring harmony to your project.
Merge conflicts occur when Git finds incompatible changes in the files being merged. But don't worry; Git will guide you on your quest to resolve them.
When a merge conflict arises, Git will mark the conflicting lines in your files. It's your job to decide what stays and what goes. Open the conflicting file, and you'll see something like this:
<<<<<<< HEAD
Your changes
=======
Their changes
>>>>>>> their-branch
Here, "Your changes" are the modifications from your branch, and "Their changes" are from the other branch. Decide which changes to keep, then remove the conflict markers (<<<<<<<, =======, >>>>>>>) accordingly.
Once you're done, save the file, then add and commit the changes. Huzzah! 🎉 You've resolved the merge conflict and united the branches!
Task-01
Solution
Task-02
Solution
Task-03
Solution
Conclusion✨
Congratulations, young padawans of Git! You have now mastered the magical arts of cherry-picking, stashing, and resolving merge conflicts. Always remember, Git is your trusty companion in your IT adventures, helping you collaborate and create wonders in the world of software development. Happy coding! 🚀