# Advance Git & GitHub: 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680144946819/8fb07b9a-7fdd-4c27-b4e7-2304b51a06b4.jpeg align="center")

<mark>Note:</mark> Stashing is a useful tool for temporarily storing changes, but it should not be used as a replacement for committing changes to version control. Make sure to commit your changes regularly to keep track of your work and collaborate with others.

## 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 <commit_hash>` 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 it can proceed with the merge/rebase.

For example, if two developers make changes to the same file in different ways, Git will not know which version to keep and will flag a conflict. Resolving conflicts in Git involves identifying the conflicting changes, deciding how to merge them, and then committing the changes.

`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/v1680158548319/dfd8c139-6584-42ee-a8ab-02788319b87d.jpeg align="center")

* Use `git stash` to save the changes without committing them.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680158531693/b284f218-1cea-44ce-bd93-55fead7f8bfd.jpeg align="center")

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680158510283/756a8046-5a7d-4f7c-9182-7469a11d1a0e.jpeg 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/v1680158494850/22b9d912-1b6f-4385-b69f-4263f2a8d141.jpeg align="center")

All the commits can be viewed using the `git log`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680158479864/0d4f04a4-d650-4e34-8164-8d49fd27826e.jpeg align="center")

# Task-02

* In version01.txt of 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”
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680159955349/90f0adcf-a91f-4bf7-b2eb-8fffb36e4e44.jpeg align="center")

The file is committed accordingly, and each commit message can be viewed in the `git log`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680159696544/22dd4b46-35a9-44d1-939e-cc97f4b2eb78.jpeg 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`).
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1680160233208/613b6d6c-a186-407d-9842-104ebd91337c.jpeg 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/v1680163212933/0c31af9e-560b-4f4b-888b-4733b8f5d959.jpeg align="center")

### Reference: [visit](https://youtu.be/apGV9Kg7ics)

###########################################################

Thanks for reading! Hope you find this helpful.

Happy learning!!! Suggestions are welcome.

for code - [GitHub](https://github.com/SumitRamchandra/DevOps/tree/main)

~[Sumit](https://www.linkedin.com/in/sumit-ghorpade-425803129/)

Thank You - @[Shubham Londhe](@TrainWithShubham)
