Day 11 of #90daysofdevops
Hey Techies! Welcome to this blog
In this blog, we are going to Advance in Git and GitHub for DevOps engineers Part-2
Understanding Git Stash
Git Stash: A Crafty DevOps Tool
Sometimes you want to switch the branches, but you are working on an incomplete part of your current project. You don't want to make a commit of half-done work. Git stashing allows you to do so. The git stash command enables you to switch branches without committing to the current branch.
The below figure demonstrates the properties and role of stashing concerning repository and working directory.
# Create a new branch and make changes
git checkout -b feature-branch
# Make changes...
git stash save "Work in Progress"
# Switch to a different branch, make changes, and commit
git checkout main
# Make changes...
git commit -m "New changes in main branch"
# Bring back the stashed changes
git stash pop
Understanding Git Cherry-Pick
Cherry-Pick: Selective Commit Magic
Cherry-picking in Git stands for applying some commit from one branch into another branch. In case you made a mistake and committed a change into the wrong branch, but do not want to merge the whole branch. You can revert the commit and apply it on another branch.
# Create two new branches and make commits
git checkout -b branch-1
# Make commits...
git checkout -b branch-2
# Make commits...
# Cherry-pick specific commits to another branch
git checkout target-branch
git cherry-pick <commit_hash>
Resolving Conflicts: Navigating Git Harmony
Mastering Conflict Resolution
Conflicts are an inevitable part of branching, merging, and rebasing. Git equips you with tools to gracefully resolve conflicts and proceed with your version control journey.
Theoretical Insights:
Conflicts in Git:
Explore why conflicts occur during merges and rebases.
Utilize commands like
git status
,git diff
, andgit add
to navigate and resolve conflicts.
Practical Task:
Resolving Conflicts:
Create conflicts intentionally.
Resolve conflicts using
git status
,git diff
, andgit add
.
Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.
Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.
Happy Learning!
~kritika :)