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

### **Git Stash**

`Git stash` is a command that allows you to temporarily save changes you have made in your working directory, without committing them. This is useful when you need to switch to a different branch to work on something else, but you don't want to commit the changes you've made in your current branch yet.

To use Git stash, you first create a new branch and make some changes to it. Then you can use the command git stash to save those changes. This will remove the changes from your working directory and record them in a new stash. You can apply these changes later. git stash list command shows the list of stashed changes.

You can also use git stash drop to delete a stash and git stash clear to delete all the stashes.

## Cherry-pick:

`Git cherry-pick` is a command that allows you to select specific commits from one branch and apply them to another. This can be useful when you want to selectively apply changes that were made in one branch to another.

To use git cherry-pick, you first create two new branches and make some commits to them. Then you use the git cherry-pick &lt;commit\_hash&gt; command to select the specific commits from one branch and apply them to the other.

## Resolving Conflicts:

Conflicts can occur when you merge or rebase branches that have diverged, and you need to manually resolve the conflicts before git can proceed with the merge/rebase. git status command shows the files that have conflicts, the git diff command shows the difference between the conflicting versions and the git add command is used to add the resolved files.

# Task-01

* Create a new branch and make some changes to it.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681051702886/fab00e8f-e565-49b2-bc17-0b5246c8e73a.png align="center")
    
* Use git stash to save the changes without committing them.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681051729693/dd2d0d83-12ac-4f57-9371-d05bb2a2381d.png align="center")
    
* Switch to a different branch, make some changes and commit them.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681051750410/7edada47-61d6-42e9-b5fc-723727c6a900.png align="center")
    
* Use git stash pop to bring the changes back and apply them on top of the new commits.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681051777433/70ccf4fd-61f2-431c-9350-4789f48b3406.png align="center")
    

# 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&gt;&gt; "After bug fixing, this is the new feature with minor alteration”
    
    Commit this with message “ Added feature2.1 in development branch”
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681052051242/23dbe1fb-df55-4bc0-b27e-9de48c6fb14c.png align="center")
    
* Line3&gt;&gt; This is the advancement of previous feature.
    
    Commit this with message “ Added feature2.2 in development branch”
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681052253864/0b527f12-39a2-4581-98fc-771da1e12ef7.png align="center")
    
* Line4&gt;&gt; Feature 2 is completed and ready for release
    
    Commit this with message “ Feature2 completed”
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681052461520/f97e785b-9ce6-4e08-b0db-6ba06334b050.png align="center")
    
* All these commits messages should be reflected in the Production branch too which will come out from the Master branch (Hint: try rebase).
    
* **<mark>In my case the default branch is</mark>** **<mark>main</mark>**
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681052842202/aa173402-93fe-4dc4-b8f2-478556d53c53.png align="center")
    
    **<mark>After rebasing:</mark>**
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681052871052/8ae4cd6f-1bc8-497a-adbc-d00bfa293549.png align="center")
    

# Task-03

* In the Production branch, Cherry pick Commit “Added feature2.2 in development branch”
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681054356674/30f6d941-5748-447b-b31b-751e8358a8b5.png align="center")
    
    **<mark>There was a conflict that arose while cherry picking</mark>**
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681054403479/e6b9e322-bd01-4454-ac34-3efb493d116c.png align="center")
    
    **<mark>After resolving conflict</mark>**
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681054445792/12469fa0-5eac-4c25-af06-46c8c462738f.png align="center")
    
* Now add the below lines in it:
    
* The line to be added after Line3&gt;&gt; This is the advancement of previous feature
    
* Line 4&gt;&gt;Added few more changes to make it more optimized.
    
* Commit: Optimized the feature
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1681054727845/9a213ada-215f-46b0-8d82-dbe929fb15a3.png align="center")
    

\&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Thank you for reading! :-) &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
