stash – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Fri, 29 Oct 2021 08:49:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Git Stash Changes https://tecadmin.net/git-stash-changes/ https://tecadmin.net/git-stash-changes/#respond Wed, 27 Oct 2021 15:08:00 +0000 https://tecadmin.net/?p=28241 Ever had a need to temporarily store changes that you made to your code? Without committing it? For example, you were in the middle of branch editing and someone asked you to collaborate on a different one? If you didn’t, you most likely will somewhere down the road in your developer career. At that point, [...]

The post How to Git Stash Changes appeared first on TecAdmin.

]]>
Ever had a need to temporarily store changes that you made to your code? Without committing it? For example, you were in the middle of branch editing and someone asked you to collaborate on a different one? If you didn’t, you most likely will somewhere down the road in your developer career. At that point, it will be extremely useful to know how to use git stash. With the help of that command, you can temporarily store your current work to jump onto something else. Read on and find out how to Git stash changes.

How to Use Git Stash Command to Temporarily Save Your Changes

Okay, so picture this scenario. You are currently working on a piece of code that should bring a new feature to the application. All of a sudden, you urgently have to assist one of your co-workers with a bug that they found in a completely different branch. The first thing that you would want to do is to check which files you recently modified in the branch on which you are currently working. You can do that with a simple command.

git status 

This command will show you modified files. Below, you can find an example of the output.

Output:
modified: app_layer.php modified: readme.txt modified: functions.php

Of course that you don’t want to lose your work on these files, but on the other hand you can’t just commit them. And that is where git stash shines!

The command itself is extremely easy and straightforward. An example is below.

git stash 

The output will look similar to the one below.

Output:
Saved working directory and index state WIP on master: 3tjaq12w Implement the new login box HEAD is now at 3tjaq12w Implement the new login box

And that’s it! All your work on the current branch is saved in some sort of clipboard. Feel free to start working on whatever popped up in the meantime.

Speaking of pop, here’s how you can return to the place where you left off once you are ready to continue. Simply type this into your terminal.

git stash pop 

After the command above, you will be returned to your last saved state.

Conclusion

You’ll agree with us when we say that this is a very simple Git command to learn and it is of real value to having knowledge of it. We certainly hope that you’ll find a good use for what you learned today. Remember, developing is a never-ending course when it comes to learning.

The post How to Git Stash Changes appeared first on TecAdmin.

]]>
https://tecadmin.net/git-stash-changes/feed/ 0