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

### ✅Introduction💥

The "Git stash" command is used in Git version control to temporarily save the files. This command allows the users to save unfinished work Changes that you have made to your working directory but do not want to commit immediately.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691420627401/d7345e35-7c8f-4b38-8fe0-14466f3bb760.png align="center")

Use of Git stash command:

**Save Changes**: To stash your changes, run:

```plaintext
git stash save "message"
```

**Check Stash List**: You can view your list of stashes using:

```plaintext
git stash list
```

**Apply Stash**: To apply your stashed changes back to your working directory, use:

```plaintext
git stash apply stash{n}
```

Replace n with the index of the stash, you want to apply.

**Pop Stash**: If you want to apply and remove the stash from the list at the same time, you can use:

```plaintext
git stash pop stash{n}
```

**Drop Stash**: If you decide you no longer need a particular stash, you can remove it from the stash list:

```plaintext
git stash drop stash{n}
```

**Clear Stashes**: To clear all stashes, you can use:

```plaintext
git stash clear
```

The "Git cherry-pick" command in Git is used to apply the changes of a specific commit to your current branch. This can be useful when you want to pick and apply only certain commits from one branch onto another, without merging the entire branch.

![](https://cdn.filestackcontent.com/NxNdKJBDSSCxbVU7bZiw align="left")

Use of Git cherry-pick command:

**Switch to the Target Branch**: Make sure you're on the branch where you want to apply the changes.

```plaintext
git checkout target-branch
```

**Cherry-Pick the Commit**: Use the following command to apply the changes from the desired commit onto the current branch:

```plaintext
git cherry-pick commit-hash
```

**Resolve Conflicts (if any)**: If there are any conflicts during the cherry-pick process (when the same lines were modified in both the source and target branches), you'll need to resolve these conflicts manually. After resolving conflicts, continue the cherry-pick process by running:

```plaintext
git cherry-pick --continue
```

### ✅Task-01

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.

step1:to create branch command is:

```plaintext
git branch <branch name>
```

step2:create a file, do some changes in the file, add it to Git and perform stash command:

```plaintext
vi file1.txt
git add file1.txt
git stash
```

step3:switch to another branch command is

```plaintext
git checkout <branch name>
```

step4:create another file and do some changes to the file, and add it to git.

```plaintext
vi file.txt
git add file.txt
```

step5:apply and remove the stash from the list command is

```plaintext
git stash pop
```

step6:then commit it to the git.

```plaintext
git commit -m <add some message>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691504243371/92b0b2a1-d672-4b62-a3e2-daa5764e8719.png align="center")

### ✅Task-02

* In version01.txt of the development branch add the 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 alterations”
    
    Commit this with the message “ Added feature2.1 in development branch”
    
* Line3&gt;&gt; This is the advancement of the previous feature
    
    Commit this with the message “ Added feature2.2 in development branch”
    
* Line4&gt;&gt; Feature 2 is completed and ready for release
    
    Commit this with the message “ Feature2 completed”
    
* All these commits messages should be reflected in the Production branch too which will come out from the Master branch (Hint: try rebase).
    
    step1: create a branch called "development" command is
    
    ```plaintext
    git branch development
    ```
    

step2:create a file "version1.txt" and do some changes to the file and commit Changes to Development.

```plaintext
vi version1.txt
git add version1.txt
git commit -m <add message>
```

step3:Create a Production Branch from Master:

```plaintext
Switch to the master branch-
git checkout master
Create a new Production branch from master-
git checkout -b production
```

step4:rebase the production branch onto the development branch to include the commits from development:

```plaintext
git rebase development
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691506737379/8b9331cc-93b4-4a4d-859c-062aeda6fb8a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691506884285/7593b631-1315-4252-b51a-7c261b1d1944.png align="center")

### ✅Task-03

* In the Production branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:
    
* 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/v1691507301195/402ed914-2b9d-46f1-acb1-f01d2ced8913.png align="center")
