What is stash in git for beginners

Views:
 
Category: Entertainment
     
 

Presentation Description

For better understanding what is stash in git suppose you are a developer. You came in office and start coding. From last 2-3 hours you are working on your code. But your task is not completed yet means still you are continuously working on your code.

Comments

Presentation Transcript

slide 1:

LinuxDady.Com What is stash in git and its use case for beginners For more information visit https : //linux dady .com

slide 2:

What is stash in git and its use case for beginners BY DEEPAK KUMAR · PUBLISHED OCTOBER 31 2019 · UPDATED OCTOBER 31 2019 Today we are going to learn what is stash in git and what are the role of git stash in developer’s daily routine life. Why developers should use git stash instead of git new branch and what are the advantages of using stash area. what is stash in git For better understanding what is stash in git suppose you are a developer. You came in office and start coding. From last 2-3 hours you are working on your code. But your task is not completed yet means still you are continuously working on your code. Means while time you got a ticket and your manager says Harry do it first on high priority because this is production issue. Now in this situation Harry have two option. He can discard his changes from code. But he can’t do it because he is working on it from last 2-3 hours. Second option is he can commit his code into branch but his task is not competed yet still he is working on it when he got the ticket. But harry compulsion is he have to work on production ticket first on high priority. But if he will switch from his current branch to another branch and commit anything into that branch his all previous branch changes will lost. So to resolve this issue Harry needs an alternate and that alternate is git stash. By using this we can save our incomplete task into stash area and can work parallelly on another issue. Demo of stash area Let have a demo we will write some code for demo purpose after that we will save and roll back that code from stashing area. Let’s do it. 1 vim demo

slide 3:

suppose we have written some code into this file according to our requirement. Mean while we got a ticket regarding production issue. My code is pending so I cannot commit it. So let’s save our task into stash area. So first check status of our code 1 2 3 git status -s git stash save git status -s When we will check git status it is showing M means modified not committed yet. But when we check git status after saving code into stash area then it is showing repository in clean state. Now we can switch to any branch and can work on open issue because our changes has been saved into stash area. Click Read: – What is git and basic terminology for DevOps engineers Click Read: – Explain git workflow for beginners step by step Click Read: – How to add ssh key on GitHub step by step Roll back changes from stash area Now suppose after saving our code into stash area we have worked on bugs that was open in production and fixed that bugs now switch to branch in which

slide 4:

we were working and roll back our 2-3 hours work from stash area. In my case stage is the developers branch name where developer were working change accordingly. 1 2 3 git checkout stage git status -s git stash list 1 2 git stash show stash0 git stash pop stash0 Our pending task has been rolled out from stashing area. Now we can work as before. Now I think you have understood very well about what is stash in git. But Now my question is why we should use stash area instead of branch. We are using git stash because this is just a convenience way. Since branches are so easy to manage in git I personally almost prefer creating a new temporary branch than stashing but it’s depend on choice mostly. There is no compulsion you have to use git stash only. Go ahead according to situation and taste means we can use anyone from stash area or git branch its depend on our choice. Biggest advantage of git stash area

slide 5:

One important advantage of using stash area is we can keep our commit history clean by avoiding unnecessary commits just for the sake of switching from one branch to another. Conclusion and all about what is stash in git In this tutorial we have discussed what is stash in git and it’s use cases in a developer life. But still anyone have query write me in comment box. I will try my best to resolve that query. Kindly keep answering below interview question in comment box. These questions will help a lot of those engineers which are doing preparation for interview. Also you can add interview question if you have faced ever. Interview question related to stash area 1. What is the difference between git stash and git staging 2. Why we are preferring stash area instead of new branch 3. How to roll back our pending task from stash area 4. What is meaning of clean state and how we will check repository status

authorStream Live Help