Demystifying Git: Stash, Basic workflow in the four areas

Sai Charan Adurthi
3 min readJun 30, 2020

--

This article is a part of a series of articles on Git.

In the previous article “Demystifying Git: Four Areas of Git”, I have discussed

  • Working directory
  • Index
  • Repository

Now, we will look into the fourth area Stash and then understand how a git command makes data flow between the four areas.

Git Stash

Git takes all the data from the working directory and the index and copies that to the the stash and also checks-out current commit to the working directory and index

Stash is like a clipboard for a project. Each stash copy gets a serial id, so that we can store any number of copies of commits.

four areas in git
git stash

in above picture, i had created two files “helloworld.txt and readme.md” in my working directory.

First I had created HelloWorld.txt and then added it to index. Then, committed it.

Next, I had created Readme.md and then staged it, but didnt want to commit it as i have few more changes in mind that need to be done before this change.

Hence, i stash the changes in index.

Sometimes, we want to stash unstaged changes as well. Example: imagine we modified Helloworld.txt file in working directory but didn't stage it.

Then we will use “git stash — — include-untracked” command.

Basic Workflow in the four areas

To understand any git command, ask yourselves the following two questions:

  1. How does this command move information across the four areas ?
  2. How does this command change the repository ?

Moving Data to the Right

The commands “git add, git commit” move data from left to right.

we create a file in the working directory, then we add / stage it to index / staging area. Once we are sure about the changes, we commit the changes.

moving data from left to right in git

Moving Data to the left

The command “git checkout” moves data from right to left.

We checkout to a specific commit or branch in the repository and accordingly the HEAD points to that object.

Then, the repository moves the data in that object to the index and working directory.

moving data from right to left

In the next article we will discuss git reset command and resolving conflicts.

--

--

Sai Charan Adurthi

Tech Head | Fitness Freak 🏋| Gallivanter✈️🏕| #charanthecsguy