๐๐ Day 11 Task: Advanced Git & GitHub for DevOps Engineers: Part-2 ๐๐


Introduction:
Welcome back, DevOps Engineers! In this part of the series, we will dive deeper into some advanced Git concepts and commands that will help streamline your development workflow. We will cover Git stash, Git cherry-pick, resolving conflicts, and a practical hands-on exercise to reinforce your learning.
Git Stash:
๐ฆ
git stash
saves changes temporarily without committing.๐ Use
git stash pop
to apply stashed changes later.๐
git stash list
shows the list of stashed changes.โ
git stash drop
deletes a stash.โ
git stash clear
deletes all stashes.
Cherry-pick:
๐
git cherry-pick
applies specific commits to another branch.๐ Create two branches and make commits on each.
๐ Cherry-pick the desired commits.
Resolving Conflicts:
๐
git status
checks for conflicting files.๐
git diff
shows differences in conflicting versions.โ๏ธ Manually edit conflicting files.
โ๏ธ
git add
marks resolved files.
Task-01: Git Stash and Applying Changes
๐ Create a new branch: Start by creating a new branch named "feature-branch" using
git checkout -b feature-branch
.๐ ๏ธ Make some changes: Modify the necessary files in the new branch.
๐ฆ Stash your changes: Use
git stash
to save the changes without committing them.๐ Switch to a different branch: Now, switch to a different branch, for example, "development" using
git checkout development
.๐พ Commit changes: In the "development" branch, make some changes and commit them using
git commit -m "Your commit message"
.๐ค Apply stashed changes: Return to the "feature-branch" using
git checkout feature-branch
, then usegit stash pop
to apply the stashed changes on top of the new commits.
Task-01: Git Stash and Applying Changes
# Task-01: Git Stash and Applying Changes
# Create a new branch and switch to it
git checkout -b feature-branch
# Make changes to the necessary files
# ...
# Stash your changes
git stash
# Switch to a different branch (e.g., development)
git checkout development
# Make some changes in the development branch and commit them
# ...
# Apply stashed changes on top of the new commits
git checkout feature-branch
git stash pop
Task-02: Cherry-pick and Rebase
๐ Add lines to "version01.txt" for feature2.1 and commit.
๐ Add more lines for feature2.2 and commit.
๐ Finalize feature2 and commit.
# Task-02: Cherry-pick and Rebase
# Switch to the development branch
git checkout development
# Modify the version01.txt file as described in the task
# ...
# Commit changes for feature2.1
git add version01.txt
git commit -m "Added feature2.1 in development branch"
# Add more lines for feature2.2
# ...
# Commit changes for feature2.2
git add version01.txt
git commit -m "Added feature2.2 in development branch"
# Add final lines for feature2 completion
# ...
# Commit changes for feature2 completion
git add version01.txt
git commit -m "Feature2 completed"
Task-03: Cherry-pick in the Production Branch
๐ Switch to "production" branch.
๐ Cherry-pick commit "Added feature2.2 in development branch".
๐ Add more lines after cherry-picked commit.
โ๏ธ Commit changes for the optimized feature.
# Task-03: Cherry-pick in the Production Branch
# Switch to the production branch
git checkout production
# Cherry-pick the commit "Added feature2.2 in development branch"
git cherry-pick <commit_hash> # Replace <commit_hash> with the actual commit hash
# Add more lines after the cherry-picked commit
# ...
# Commit changes for the optimized feature
git add version01.txt
git commit -m "Optimized the feature"
Conclusion
Git stash ๐ฆ, cherry-pick ๐, and conflict resolution ๐ง are essential DevOps superpowers! Stash away changes, cherry-pick specific commits, and resolve conflicts like a pro ๐๐ง. Master these Git tricks to level up your DevOps skills and collaborate effectively ๐ฅ. Happy coding! ๐๐
๐ข Stay in the โ๏ธ cloud loop and blast off into the ๐ DevOps universe! Join me on Hashnode, where I share my latest insights and articles about all things cloud and DevOps. Let's connect on LinkedIn (https://www.linkedin.com/in/nirmal-mahale-605565215/) and explore the boundless possibilities of the tech cosmos together. ๐ And hey, if you want to peek under the hood of my projects, hop on over to my GitHub (https://github.com/nirmal7030). ๐ ๏ธ
Subscribe to my newsletter
Read articles from Nirmal Mahale directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Nirmal Mahale
Nirmal Mahale
Passionate about Python, Cloud Computing, and DevOps. Architecting robust cloud solutions, mastering AWS & Azure, and automating with cutting-edge DevOps tools. Join me on this journey of innovation and collaboration. Let's shape the future together!