Version control systems are essential tools for software development. They enable change tracking, efficient collaboration, and maintaining code ...
integrity. One of Git's lesser-known but incredibly powerful features is the "stash" command. This article explains what stashing is, how it works, and its practical applications in your workflow.1. What is Stashing?
2. Practical Examples in Daily Workflow
3. Conclusion
1.) What is Stashing?
Stashing is a feature in Git that allows you to temporarily save changes made to your working directory and branch off without committing them. This can be particularly useful when you need to switch branches or work on something else but don't want to commit the current set of changes.
Basic Usage
To stash your changes, simply use the following command in your terminal:
git stash save -your-message-
This will take all the uncommitted changes and store them in a stack, ready to be applied later. You can also include a message with `save` to identify what changes were made when you look at your stashes later.
Viewing Stashed Changes
To see the list of stashes you've created, use:
git stash list
Each entry in this list will show a unique identifier followed by -stash@{...}- where `...` is an index number. This can be useful if you have multiple stashes and need to apply or drop specific ones.
Applying Stashed Changes
To reapply the most recent stash, use:
git stash apply
If you want to apply a specific stash by its identifier (e.g., `stash@{1}`), replace `stash@{1}` in the command with your desired stash reference.
Dropping Stashed Changes
To remove a stash from the list, use:
git stash drop stash@{0}
This will delete the specified stash. If you want to clear all stashes, you can use:
git stash clear
Creating and Applying Stashes During Conflicts
When working on a branch that has uncommitted changes but also conflicts with upstream branches, using `stash` can help manage these situations smoothly. You can create a stash before merging or pulling updates from the main branch:
git stash save -before-merge- git pull origin main --rebase # Resolve conflicts if any git stash apply
This way, you keep your changes separate while still being able to update your local repository.
2.) Practical Examples in Daily Workflow
Scenario 1: Working on a New Feature While Having Uncommitted Changes
You start working on a new feature but have several uncommitted changes that you aren't ready to commit yet. You can stash these changes and work on the new feature branch without committing your current modifications:
git checkout -b new-feature # Make changes related to the new feature git add . git commit -m -Start working on new feature- git stash save -uncommitted-changes-
Later, you can switch back to `main` and apply your stashed changes:
git checkout main # Work on main branch... git pull origin main # Resolve conflicts if any git checkout -b new-feature git stash apply
Scenario 2: Testing a Hotfix While Having Uncommitted Changes in Development Branch
While testing a hotfix, you realize that your development branch has uncommitted changes that might interfere with the test environment. You can stash these changes and then reapply them after finishing the hotfix:
git checkout develop # Make necessary changes for hotfix... git add . git commit -m -Hotfix changes- git stash save -develop-changes- git checkout main # Apply stashed changes to test environment git stash apply
3.) Conclusion
Stashing is a powerful yet simple tool in Git that can help you manage your workflow more efficiently, especially when dealing with multiple branches or urgent hotfixes. Understanding how and when to use `stash` can significantly improve your productivity and reduce the stress of managing complex codebases across different stages of development.
The Autor: LeakLord / Diego 2026-03-15
Read also!
Page-
Virtual Machines on Windows: Hyper-V vs. VirtualBox
Virtualization has become an essential aspect for efficient resource utilization and flexibility in computing environments. Two popular options for virtual machines (VMs) on Windows are Microsoft Hyper-V and Oracle VirtualBox. Each tool ...read more
The Ethics of Automating Creative Feedback
Automation has become a buzzword, especially in the area of feedback mechanisms. While automation can significantly increase productivity and efficiency, it also raises significant ethical questions that must be considered to ensure ...read more
The Future of "Free": More Data, Less Privacy, and Perpetual Harvesting
One of the most significant changes is the shift from paid software to free apps with in-app purchases or advertising. This model has been a staple ...read more