Advance Git & GitHub for DevOps Engineers - Part 2
#90DaysofDevOps Challenge - Day 11
▶What is Git Stash?
It enables you to switch branches without committing to the current branch.
The below figure demonstrates the properties and role of stashing concerning the repository and working directory.
Generally, the stash means "store something safely in a hidden place". The sense in Git is also the same for stash; Git temporarily saves your data safely without committing.
▶What is Cherry-pick?
It is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick
can be useful for undoing changes. For example, say a commit is accidentally made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.
▶How to resolve conflicts?
It can occur when you merge or rebase branches that have diverged, and you need to manually resolve the conflicts before Git can proceed with the merge/rebase. The git status command
shows the files that have conflicts, git diff command
shows the difference between the conflicting versions and git add
command is used to add the resolved files.
▶Task-01
Create a new branch and make some changes to it.
Use git stash to save the changes without committing them.
Switch to a different branch, make some changes and commit them.
Use git stash pop to bring the changes back and apply them on top of the new commits.
▶Task-02
In version01.txt of the development branch add the below lines after “This is the bug fix in development branch” that you added in Day10 and reverted to this commit.
Line2>> After bug fixing, this is the new feature with minor alterations”
Commit this with the message “ Added feature2.1 in development branch”
Line3>> This is the advancement of the previous feature
Commit this with the message “ Added feature2.2 in development branch”
Line4>> Feature 2 is completed and ready for release
Commit this with the message “ Feature2 completed”
All these commits messages should be reflected in the Production branch too which will come out from the Master branch (Hint: try rebase).
▶Task-03
In the Production branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:
The line to be added after Line3>> This is the advancement of the previous feature
Line 4>>Added a few more changes to make it more optimized.
Commit: Optimized the feature
Thank you for taking the time to read this article.