Practical Stash Workflows
Common Development Scenarios
Scenario 1: Switching Branches Mid-Development
## Current work in progress
git status
## Stash current changes
git stash save "Incomplete feature work"
## Switch to another branch
git checkout another-branch
## Return and restore work later
git checkout original-branch
git stash pop
Scenario 2: Emergency Hotfix Workflow
graph TD
A[Working Branch] -->|Urgent Issue| B[Stash Current Work]
B -->|Create Hotfix Branch| C[Develop Fix]
C -->|Commit Fix| D[Merge to Main]
D -->|Restore Stashed Work| E[Continue Development]
Collaborative Stash Strategies
Team Collaboration Workflow
Workflow Step |
Git Command |
Purpose |
Stash Changes |
git stash save |
Preserve local modifications |
Create Feature Branch |
git checkout -b feature-branch |
Isolate development |
Apply Stashed Work |
git stash apply |
Restore previous work |
Complex Stash Handling
## Stash with include/exclude options
git stash push -m "Partial work" -- path/to/specific/files
git stash push -m "Exclude test files" -- . ':!*.test.js'
Advanced Stash Techniques
Stash Inspection and Management
## Show contents of a specific stash
git stash show -p stash@{0}
## Create a branch from a stash
git stash branch recovery-branch stash@{1}
Handling Multiple Stashes
graph LR
A[Stash Stack] -->|List| B[Stash Entries]
B -->|Select| C[Apply/Pop Specific Stash]
C -->|Manage| D[Drop/Clear Stashes]
Workflow Best Practices
- Use descriptive stash messages
- Regularly clean up unnecessary stashes
- Understand context before applying stashes
Stash Cleanup
## Remove specific stash
git stash drop stash@{2}
## Clear all stashes
git stash clear
Real-World Workflow Example
## Start working on a feature
git checkout -b feature-authentication
## Midway, encounter urgent bug
git stash save "Incomplete auth feature"
## Switch to main branch
git checkout main
## Create hotfix branch
git checkout -b critical-security-fix
## Develop and commit fix
git commit -m "Patch critical security vulnerability"
## Return to feature branch
git checkout feature-authentication
## Restore stashed work
git stash pop
LabEx recommends practicing these workflows to enhance development efficiency and maintain clean version control practices.