Using Git stash

I started using Git recently and I have to say I’m really impressed. Today I want to write about one of its features: Git stash.

Git stash is a “place” where you can store files temporarily before¬†committing¬†them to your repository. Imagine you are working on a branch, called “my-new-super-awesome-feature”. Unluckily, while you are in the middle of the development process, you have to start working on a critical issue on your application. What should you do with all changes you have made before switching the branch?

Of course, you can commit to your feature branch and then switch to the branch where you are going to fix the bug, but there is cleaner solution: stash your changes. Using this feature you could save all changes you had made on your working directory by executing:

git stash save "Current status of my new super awesome feature #WIP"

That command returns your working directory to the state it was after your latest commit, so you can do any action in a clean working directory. You can list all your stashed changes by using:

git stash list

Yes, you have read right. You can store more than one stash of changes!

Once you are ready to work again on your new awesome feature, you can pop or apply your stash to the working directory executing:

git stash pop <stash_id>

You can also throw your changes away with:

git stash drop <stash_id>

If you want to learn more about this nice feature, you can do it by typing git help stash in your terminal.

Welcome!

Hello everyone!

My name is Edmundo Alvarez and this is my personal blog. I want to give you a warm welcome, dear reader.

In first place, let me introduce myself: I am a 26-year-old computer scientist born in Madrid who currently reside in Hamburg and work at XING. I like learning new things, technology, music, films and series among other things.

This place will be filled with different things I work on and some thoughts I have about them. That is, I will use this blog mainly to post computing related stuff, although you may find some other things from time to time.

I hope you enjoy the blog and you participate writing some comments.

Talk to you soon!

Follow

Get every new post delivered to your Inbox.