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

## **Git Stash:**

* Let's first discuss what we mean by *'****stash****'*, i.e. store something safely in a hidden place. Hence [`git stash`](https://www.golinuxcloud.com/git-stash-explained-in-detail-with-examples/) is a command temporarily saves your data 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.
    
* ***Git stash*** has the following options available
    
    * **git stash list:** This returns a list of your saved snapshots in the format `stash@{0}:`
        
        Syntax: **git stash list**
        
    * **stash pop:** To bring the changes back and apply them on top of the new commits.
        
        Syntax: **git pop**
        
    * **git stash apply:** Applies the changes and leaves a copy in the stash
        
        Syntax: **git stash apply &lt;stash-name&gt;**
        
    * **git stash or git stash save &lt;message&gt;:** Store the changes to (stash)
        
        Syntax: **git stash save &lt;message&gt;**
        
    * **git stash clear:** The git stash clear command allows deleting all the available stashes at once.
        
        Syntax: **git stash clear**
        
    * **git stash drop &lt;name of the stash&gt;:** To delete specific stash from the stash list
        
        Syntax: **git stash clear &lt;name of the stash&gt;**
        
    * **git stash branch &lt;branch-name&gt;:** which creates a new branch for you with your selected branch name
        
        Syntax: **git stash branch &lt;branch-name&gt;**
        

## **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, without merging the entire branch.
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682565300340/39f982ab-6e5f-4078-9330-ebf0e44ebd43.jpeg align="center")
    

## **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.
    

# **Task1:-**

Create a new branch and make some changes to it.

git checkout -b &lt;branch-name&gt;

Use git stash to save the changes without committing them.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682565759110/97b52958-26df-4d78-b207-600ebdc48883.png align="center")

* Switch to a different branch, make some changes, and commit them.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682566254407/3a9c1e73-4865-4d54-a88d-2d8b91ca0dbe.png align="center")
    
    * Use git stash pop to bring the changes back and apply them on top of the new commits.
        
        `git stash pop`
        
    * ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682567187713/a15c7653-da0d-4c8d-895a-8c9845a39e2c.png align="center")
        

# **Task2:-**

* In version01.txt of the development branch add the below lines after “This is the bug fix in the development branch” that you added in Day10 and reverted to this commit
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682567667354/282a0832-6fa8-4c66-b17e-0f160b9bbfc2.png align="center")
    
* Line2&gt;&gt; This is the advancement of the previous feature
    
    Commit this with the message “ Added feature2.2 in development branch”
    
* Line3&gt;&gt; Feature 2 is completed and ready for release
    
    Commit this with the message “ Feature2 completed”
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682568251657/93d0eadf-569c-42f3-9028-0e33a2f26212.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 to rebase)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682568384886/5cd8c93a-a94d-4e15-8be0-dd18c6c746bb.png align="center")
    
    ## **Task3:-**
    
* * In the Production branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682568728632/80b7b5d3-943c-4919-9468-353220b47ee6.png align="center")
        
        * The line to be added after Line3&gt;&gt; This is the advancement of the previous feature
            
        * Line 4&gt;&gt;Added a few more changes to make it more optimized.
            
        * Commit: Optimized the feature
            
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682568899466/813c0b6a-d8ce-45e3-a9ea-b5b03a8de63e.png align="center")
