๐๐ Day 11 DevOps Challenge - Exploring Git: Stash, Cherry-Pick, and Sync Magic! ๐๐
Git Stash ๐ฆ๐
Imagine you're working on a puzzle, but suddenly you need to clean up your table. You don't want to lose your progress, so you put all the puzzle pieces in a box to keep them safe. Git stash is like that box โ it lets you store your unfinished work (changes) safely away so you can switch to a different task or branch. Later, you can take the box (stash) back out and continue where you left off.
Cherry-pick ๐โจ
Pretend you have a big basket of fruit (commits), but you only want to pick one specific type of fruit (commit) and add it to your plate. Cherry-picking in Git is similar โ you can choose a single commit from another branch and add it to your current branch. It's like taking the "cherry" commit you like and putting it into your work.
Resolving Conflicts ๐ค๐โ
Imagine you and a friend are both editing the same document. Sometimes, you might change the same sentence differently, causing a conflict. Resolving conflicts in Git is like working together to fix those conflicting changes. You both talk it out and decide which version to keep, making sure the document makes sense in the end. Similarly, in Git, when different branches have conflicting changes, you need to decide which changes to keep and which ones to discard so that your code works smoothly.
Task 1: Stash and Switch Merge Challenge
Create a new branch, make changes, and stash them.
Switch to a different branch, make changes, and commit.
Retrieve and apply stashed changes to the second branch.
# Task-01: Create a new branch and make some changes to it. git checkout -b new-branch # Make some changes to your files here # Use git stash to save the changes without committing them. git stash save "My changes on new-branch" # Switch to a different branch, make some changes, and commit them. git checkout different-branch # Make some changes to your files here git add . git commit -m "Made changes on different-branch" # Use git stash pop to bring the changes back and apply them on top of the new commits. git checkout new-branch git stash pop # Now your changes from new-branch are applied on top of the changes in different-branch
In this example:
You create a new branch called
new-branch
.You make changes to the files on
new-branch
and usegit stash
to save these changes without committing them.You switch to a different branch called
different-branch
, make changes, and commit them.Finally, you switch back to
new-branch
and usegit stash pop
to bring back and apply the changes you stashed earlier, effectively combining them with the new commits ondifferent-branch
.
Task 2: Feature Enhancement and Commit Alignment
In
version01.txt
of thedevelopment
branch, after the line "This is the bug fix in development branch" (from Day10 and reverted), add:After bug fixing, this is the new feature with minor alteration
Commit with the message: "Added feature2.1 in development branch"
Add the content:
This is the advancement of the previous feature
Commit with the message: "Added feature2.2 in development branch"
Add the content:
Feature 2 is completed and ready for release
Commit with the message: "Feature2 completed"
Ensure these commit messages are reflected in the
Production
branch, derived fromMaster
branch, using rebase.
Task-03: Production Perfection ๐๐
In the Production
branch:
Cherry-pick the commit "Added feature2.2 in development branch" to bring in the latest feature enhancement.
After the line "This is the advancement of the previous feature," add:
Line4>> Added few more changes to make it more optimized.
Commit with the message: "Optimized the feature" to ensure your project is running even smoother. ๐ ๏ธ
Remember, cherry-picking lets you pick and choose specific commits like you're selecting cherries from a tree, and optimizing features ensures your software is finely tuned for peak performance! ๐๐ง๐โโ๏ธ
We went on a Git journey, learning cool tricks! We saved changes like puzzles in a box using ๐. Cherry-picking ๐ let us pick special parts for new branches. We worked together to fix clashes ๐ค, like editing a paper with friends. Finally, we made things better ๐ ๏ธ, syncing all changes. Git's magic helps us work smoothly, like mixing colors. Our coding adventure continues! ๐๐