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

prince meeniaprince meenia
2 min read

Git Stash:

The git stash command is used to temporarily store changes that are not ready to be committed yet. This can be helpful if you need to switch branches or perform some other operation that requires a clean working directory without committing your changes.

Cherry-pick:

git cherry-pick is a command used in Git to apply a specific commit from one branch onto another branch. It allows you to pick individual commits and apply them to another branch, effectively cherry-picking only the changes you want.

Resolving Conflicts:

Resolving conflicts in Git occurs when there are conflicting changes between the branch you're trying to merge or apply changes from and the branch you're currently on. Here's how you can resolve conflicts:

Task-01 : Using Git merge command

Create a new branch and make some changes to it.

Here, I have created a new branch and made some changes and commit the changes in a file

Use git stash to save the changes without committing them.

Here, I have done the changes in feat1.txt file but not committed the changes , that is why while switching the branch to master it is showing the error.

Switch to a different branch, make some changes and commit them.

Here, to resolve that error i have used git stash command which will save the uncommitted file so that we can switch the directory to do another work.

Use git stash pop to bring the changes back and apply them on top of the new

Now Finally we can see after switching from master branch we can again switch to prod directory where the uncommitted file was saved now we have to use git stash pop command to make that file visible for the next commit, as we can see we have successfully commit feat1.txt here.

Task-02 : Using Git Cherry Pick

Here, I am in the prod branch

As shown in the logs , I have done multiple commits in the prod branch

Now , If I want all the file commits to be present in the master branch I need to merge but with merge all the unwanted files , which I dont want to merge also gets merged , so to solve this issue we bring git cherry-pick command to pick the right commit which is important.

Here, you can see the HEAD is towards master branch with the file prince.txt which is a resolved file which I want to be present in the master branch.

0
Subscribe to my newsletter

Read articles from prince meenia directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

prince meenia
prince meenia