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

Hey there! ๐
I'm Pratik R. Mandge, a DevOps Engineer passionate about all things AWS DevOps Technology. Currently on a learning adventure, I'm here to share my journey and Blog's in the world of cloud and DevOps.
๐ ๏ธ My focus? Making sense of AWS services, improving CI/CD, and diving into infrastructure as code. Whether you're fellow interns or curious enthusiasts, let's grow together in the vibrant DevOps space.
๐ Connect with me for friendly chats, shared experiences, and learning moments. Here's to embracing the learning curve and thriving in the exciting world of AWS DevOps Technology!
Follow me on LinkedIn: https://www.linkedin.com/in/pratik-mandge363
๐ธGit Stash

In simple terms, git stash is like putting your changes aside temporarily. It allows you to save your work without committing it, so you can switch to another task or branch and then come back to your changes later. It's useful when you're not ready to commit your changes but need to work on something else or clean up your workspace.
Here's a simple example of how git stash works:
Let's say you're working on a feature branch in your Git repository and you've made some changes to your files but you're not ready to commit them yet because you need to switch to another branch to fix a bug:
Check the status of your changes:
git statusStage your changes (if necessary) using
git add.Now, to stash your changes, run:
git stashThis will stash your changes, leaving your working directory clean.
You can switch to another branch now using
git checkout:git checkout other-branchAfter working on the other branch, you might decide to come back to your previous changes. To retrieve your changes from the stash, you can use:
git stash applyThis will reapply your changes to the current branch.
If you want to remove the changes from the stash after applying them, you can run:
git stash dropOr, if you want to apply and drop in a single command, you can use:
git stash pop
This is a basic example of how git stash can be used to temporarily store changes in Git. It's particularly handy when you need to switch contexts or work on something else briefly without committing half-finished work.
๐ธGit Cherry-pick

Git cherry-pick is a command that allows you to select specific commits from one branch and apply them to another. This can be useful when you want to selectively apply changes that were made in one branch to another.
Example:
Create two new branches:
git checkout -b branch1 # Make some changes and commits on branch1 git commit -am "Commit 1 on branch1" git commit -am "Commit 2 on branch1"git checkout -b branch2 # Make some changes and commits on branch2 git commit -am "Commit 1 on branch2" git commit -am "Commit 2 on branch2"Now, suppose you want to apply "Commit 2 on branch1" to
branch2:First, find the commit hash of "Commit 2 on branch1":
git logIdentify the hash of "Commit 2 on branch1".
Switch to
branch2:git checkout branch2Cherry-pick the commit from
branch1:git cherry-pick <commit_hash>Replace
<commit_hash>with the actual hash of "Commit 2 on branch1".Resolve conflicts if any. Git might pause the cherry-pick process if there are conflicts to resolve. You'll need to manually resolve these conflicts, stage the changes, and continue the cherry-pick with
git cherry-pick --continue.Once conflicts are resolved (if any), the commit from
branch1has been cherry-picked ontobranch2.๐ธConclusion
In summary,
git stashis for temporarily shelving changes, whilegit cherry-pickis for selectively applying specific commits to another branch. Both commands are valuable tools in managing your Git workflow efficiently.
I believe this blog will be really helpful, giving you fresh perspectives and teaching you something new and interesting. ๐
๐ Enjoy learning!




