Stash Changes – Git Stash

Stashing Work-in-Progress with Git Stash

git stash is used to separately manage work-in-progress (WIP) codes. When you want to switch the current branch in the middle of editing the Working Tree and INDEX, the edits can prevent you from switching the current branch (refer to the git checkout page). In that case, the git stash command is useful. The stashed lines of code are parked somewhere temporarily and make the Working Tree and INDEX clean (the Working Tree and INDEX statuses become the same as the HEAD status) so that you can switch branches.

Key Git Stash Commands

  • git stash: stash the Working Tree and INDEX
  • git stash save "[stash message]": stash the Working Tree and INDEX with a stash message
  • git stash list: list up stashed items
  • git stash apply [stash number]: restore a stashed item
  • git stash pop [stash number]: restore a stashed item and delete it from the stash list
  • git stash drop [stash number]: delete a stashed item
  • git stash clear: delete all the stashed items

For a better understanding, please go through the following practice section.

Practice

bloovee-round-icon.pngDeveloper A (Project Owner Role)

Objective:
Learn how to use the git stash commands

1. Prepare a practice directory and file

Create a new practice directory and file

For this practice, we create a new directory and file.

  • Practice project directory: git_branch_stash_practice
  • Practice file: git_branch_stash_practice.html

We create the practice directory under the main project directory (e.g., Dev_A_bloovee). Run the commands below to create the directory and file.

Command Line - INPUT
cd ~/Dev_A_bloovee
mkdir git_branch_stash_practice
cd git_branch_stash_practice
touch git_branch_stash_practice.html

Edit the practice HTML file (master and Branch_A)

For the master branch

Open the git_branch_stash_practice.html file with a text editor and make the following edits.

git_branch_stash_practice.html (master)