📦 What is Git Stash?
Source: https://www.scaler.com
git stash
is a powerful command that temporarily saves the current changes in some hidden area without committing them.It’s useful when you’re working on a feature branch and need to switch to another branch (e.g., for urgent bug fixes) without committing half-done changes. Here’s how it works:
You make some changes in your working directory.
Instead of committing them, you run
git stash
.Git saves your changes in a “stash” (a hidden area), and your working directory becomes clean (matches the latest commit).
Later, when you switch back to your original branch, you can use
git stash pop
orgit stash apply
to retrieve your saved changes and continue working on them.
🍒 What is Cherry-pick?
Source: https://geeksforgeeks.org
git cherry-pick
allows you to apply the changes introduced by an existing commit to your current branch. It’s useful when you want to selectively pick specific commits from one branch and apply them elsewhere.
⚔️ What is Git Merging Conflict?
Source: https://www.datacamp.com
A
Git merge conflict
occurs when two or more branches have conflicting changes to the same file. To resolve the merging conflict, you'll need to manually edit the file to incorporate the changes from both branches.
📝Task-01:
Create a new branch and make some changes to it.
# Syntax git checkout -b <branch_name> # Example git checkout -b stage
Use git stash to save the changes without committing them.
git stash
Switch to a different branch, make some changes, and commit them.
# Syntax git switch <branch_name> # Example git switch main
Use git stash pop to bring the changes back and apply them on top of the new commits.
git stash pop
📝Task-02:
In version01.txt of development branch add 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 alteration
Commit this with the message “ Added feature2.1 in development branch”.
Line3>> This is the advancement of 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 Production branch too which will come out from the Main branch (Hint: try rebase).
Before Rebase:
After Rebase:
📝Task-03:
Line to be added after Line3>> This is the advancement of previous feature
Line4>>Added few more changes to make it more optimized.
Commit: "Optimized the feature"
In Production branch Cherry pick Commit “Added feature2.2 in development branch” and added below lines in it:
Happy Coding :) 🙌⚡
✅ Feel free to reach out if you have any questions. I'm delighted to help! 😊
🤝 Let's Connect..!
🔗 GitHub
☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️☀️