DEV Community

Discussion on: Learn the hidden feature in Git - Stash

Collapse
 
yuvgeek profile image
Yuvaraj

It is okay to create a feature branch and work separately. Assume when you and your teammates working on the same file called abc.js and abc.html to fix a bug. One is handling UI and you will take care functional issue. You are trying to fix the functional issue but there is some dependency on UI fix as well.
You're debugging the issue by putting console.log debugger etc.. at the same time other person fixed the UI issue.

In this case, you have some unfinished code and you cannot push it until it's done. But since your issue has some partial dependency on UI fix, you need to take pull.

In this case, you can move your existing changes to stash, pull the UI fix, apply the stash, and then you can continue your work.

If you see here, you haven't pushed the code due to stash.

This is one example to use stash.

Collapse
 
baalkikhaal profile image
Sreekar Guddeti

Thank you for the helpful use case. After reading your write up and doing some look-up of git stash --help, I get a feeling that git stash and its extensions are aliases to block commands consisting of primitive git commands (like add , branch , commit, checkout, reset.

Following up the interrupted workflow use-case in the help man-page

git stash push
Enter fullscreen mode Exit fullscreen mode

is an alias for

(main) $ git branch my_wip
(main) $ git checkout my_wip
(my_wip) $ git add .\n
(my_wip) $ git commit -m 'WIP'
Enter fullscreen mode Exit fullscreen mode

where wip stands for Work in Progress, and

git stash pop
Enter fullscreen mode Exit fullscreen mode

is an alias for

(main) $ git checkout my_wip
(my_wip) $ git reset --soft HEAD^
(main) $ git checkout main
(main) $ git branch --delete my_wip
Enter fullscreen mode Exit fullscreen mode

So considering these boilerplate commands one has to type for an interrupted workflow, there definitely is some utility for using git stash push/pop :).

Some comments have been hidden by the post's author - find out more