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

👋 Hello there! I'm Vivek, a DevOps enthusiast with a keen interest in streamlining software delivery. I hold a Master's degree in Computer Applications and have a solid foundation in key technologies such as Linux, Git, Docker, Kubernetes, and AWS.
💻 My passion lies in automation, ensuring efficient and seamless processes throughout the software development lifecycle. I thrive on creating robust CI/CD pipelines that empower teams to deliver high-quality software with confidence.
🚀 Beyond the code, I enjoy the ever-evolving world of DevOps and the challenges it brings. Join me on this journey as I explore new ways to enhance software delivery and foster a culture of continuous improvement.
Let's connect, collaborate, and make the world of DevOps even more exciting together
🌱Git Stash
Git stash is a command that allows you to temporarily save changes you have made in your working directory, without committing them. This is useful when you need to switch to a different branch to work on something else, but you don't want to commit the changes you've made in your current branch yet.
Example of how git stash works:
Suppose you're working on a branch let's say feature in your Git repository and you've made changes to your files but you're not ready to commit them because you want to switch to another branch to fix a bug.
To stash your changes
git stashThis will stash your changes, and gets your working directory clean.
You can switch to another branch now using
git checkout:git checkout <Next_Branch_name>After working on the other branch, you then decided to come back to your previous changes. To retrieve your changes from the stash, you can use:
git stash popThis is a basic example of how
git stashcan be used to temporarily store changes in Git. It's very flexible when you need to switch 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 2 Branches
git checkout -b devops # Make changes and commits on devops branch git commit -m "Commit 1 on devops" git commit -m "Commit 2 on devops"git checkout -b feature # Make changes and commits on feature branch git commit -m "Commit 1 on feature" git commit -m "Commit 2 on feature"Now, apply "Commit 2 of
devopsbranch" tofeaturebranchfind the commit hash code of "Commit 2 on devops":
git log --oneline #log command show all the commits with hash IDSwitch to feature branch now:
git checkout featureCherry-pick the commit from
devopsbranch:git cherry-pick <commit_hash_ID>Resolve conflicts 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
devopswill be cherry-picked ontofeature.
🌱Conclusion
In summary, git stash is for temporarily storing changes at backstage, while git cherry-pick is for selectively applying specific commits to another branch. Both commands are valuable tools in managing your Git workflow efficiently.
Happy Learning😊




