Advance Git & GitHub for DevOps Engineers
Git Stash:
Git stash is a useful command in Git that allows you to temporarily save changes in your working directory that are not yet committed to a branch. This is often done when you're working on a particular task, but you need to switch to a different branch or perform some other operation without committing your current changes. Stashing allows you to store these changes and later apply them back to your working directory when needed.
Cherry-pick:
"Cherry-pick" is a Git command that allows you to pick and apply a single commit from one branch to another. It is useful when you want to copy a specific commit from one branch and apply it to another branch without merging the entire branch. Cherry-picking is often used to selectively incorporate changes or fixes from one branch into another.
Here's how you can use the git cherry-pick
command:
Identify the Commit: First, you need to identify the commit that you want to cherry-pick. You can find the commit hash by inspecting the branch you want to copy from, using
git log
, or through a graphical Git client.Checkout the Target Branch: Switch to the branch where you want to apply the cherry-picked commit using the
git checkout
command.Cherry-Pick the Commit: Use the
git cherry-pick
command followed by the commit hash you want to apply.This command will apply the changes introduced by the specified commit to your current branch. If there are no conflicts, Git will automatically apply the changes. If there are conflicts, you will need to resolve them just as you would during a regular merge or rebase operation.
**Commit
Resolving Conflicts:
Resolving conflicts in Git is a common task that developers face. It occurs when multiple developers are working on the same codebase and make changes to the same files at the same time. When Git tries to merge the changes from the different branches, it can't decide which changes to keep, so it creates a conflict.
There are two ways to resolve conflicts in Git: using a merge editor or using the command line.
-> Using a merge editor
->Using the command line
Today Task:)
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.
Day 11 of #90daysofDevOps
Thanks for reading
Follow me for more about DevOps♾️........
________________________________________________________________________________
#90daysHardChallenge
#Cloudcomputing
#DevOps
#Shellscripting
#TrainWithShubham