Blog: Day 11 Task: Advance Git & GitHub for DevOps Engineers: Part-2 ๐
Table of contents
No headings in the article.
๐ Introduction: Welcome back to Part 2 of our journey into the advanced features of Git and GitHub for DevOps Engineers! Today, we'll be exploring Git Stash, Cherry-pick, and resolving conflicts. Let's dive right in! ๐ช
๐ Git Stash: Have you ever needed to switch to a different branch while working on something, but you weren't ready to commit your changes yet? That's where Git stash comes to the rescue! ๐
1๏ธโฃ To use Git stash, create a new branch and make some changes. Then, run the command "git stash" to temporarily save those changes. This will clear your working directory, storing the changes in a new stash. Use "git stash list" to see all stashed changes.
2๏ธโฃ To delete a specific stash, use "git stash drop," and to clear all stashes, use "git stash clear."
๐ Cherry-pick: Sometimes, you may want to pick specific commits from one branch and apply them to another. Git cherry-pick is the way to go! ๐โจ
1๏ธโฃ Create two new branches, make some commits to them.
2๏ธโฃ Use "git cherry-pick <commit_hash>" to choose specific commits from one branch and apply them to another.
๐ Resolving Conflicts: Conflicts can arise when merging or rebasing divergent branches. Fear not, Git has your back! ๐
1๏ธโฃ When conflicts occur, use "git status" to see which files need resolution.
2๏ธโฃ Use "git diff" to view the differences between conflicting versions and resolve them manually.
3๏ธโฃ After resolving conflicts, use "git add" to add the resolved files.
๐ Task-01: Let's put our newfound knowledge into practice!
1๏ธโฃ Create a new branch and make some changes to it.
2๏ธโฃ Save the changes without committing using "git stash."
3๏ธโฃ Switch to a different branch, make some changes, and commit them.
4๏ธโฃ Use "git stash pop" to apply the stashed changes on top of the new commits.
๐ Task-02: In the "development" branch's "version01.txt," add the following lines after "This is the bug fix in the development branch":
"Line2>> After bug fixing, this is the new feature with minor alteration"
Commit this with the message "Added feature2.1 in the development branch."
Next, add the line: "Line3>> This is the advancement of the previous feature"
Commit this with the message "Added feature2.2 in the development branch."
Finally, add the line: "Line4>> Feature 2 is completed and ready for release"
Commit this with the message "Feature2 completed."
Make sure these commit messages are also reflected in the "Production" branch, which originates from the "Master" branch. You can achieve this using rebase. ๐
๐ Task-03: In the "Production" branch, cherry-pick the commit "Added feature2.2 in the development branch."
Add the following lines after "Line3>> This is the advancement of the previous feature": "Line4>> Added few more changes to make it more optimized."
Commit this with the message "Optimized the feature."
๐ Congratulations! ๐ You've successfully completed today's tasks on Advance Git & GitHub for DevOps Engineers! ๐ Keep practicing and honing your skills for an exceptional DevOps journey ahead! ๐คโจ
Stay tuned for more exciting adventures in our DevOps series! Until then, happy coding! ๐ป๐
#DevOps #Git #GitHub #CherryPick #GitStash #Conflicts #VersionControl #Coding #Development #Tech #Programming