🔧 [Git] How to Temporarily Save Changes with `git stash` While Switching Branches
Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to
1st March 2025
While working on a team project, there might be times when you're in the middle of writing code on your feat branch but need to switch to the dev branch to check something. In this case, you can use the git stash
command to temporarily save your work without committing unfinished changes.
Steps
- Save your current changes:
git stash push -m "Description of your work in progress"
- Switch to the dev branch:
git switch dev
- After checking what you need on dev, switch back to your feat branch:
git switch feat
- Restore your stashed changes:
git stash pop
The git stash pop
command applies the latest stash and automatically removes it from the stash list. If you want to apply the stash without deleting it, use:
git stash apply
What If You Have Multiple Stashes?
If you've stashed your work multiple times, you can see the list of saved stashes:
git stash list
Example output:
stash@{0}: On branch_name: Work in progress 2
stash@{1}: On branch_name: Work in progress 1
To apply a specific stash, use:
git stash pop stash@{0}
I haven't used multiple stashes much yet, but if I do, I'll come back and explain the process in more detail.
...
🐧 How to Git stash Pop Specific Stash
📈 41.27 Punkte
🐧 Linux Tipps
🔧 DAY 5 Git rebase, Git stash, Git cherry-pick.
📈 35.38 Punkte
🔧 Programmierung
🔧 Git Rebase and Git stash and Git pop -day 4
📈 35.38 Punkte
🔧 Programmierung
🔧 From Changes to Safe Keeping: Git Stash
📈 32.2 Punkte
🔧 Programmierung
🔧 How to Temporarily Store Changes in Git
📈 29.95 Punkte
🔧 Programmierung
🐧 git-stash Command in Git | Explained
📈 29.48 Punkte
🐧 Linux Tipps
🐧 Git Stash: Der nützliche Zwischenspeicher in Git
📈 29.48 Punkte
🐧 Server
🔧 Git Tags and Git Branches
📈 28.84 Punkte
🔧 Programmierung
🐧 temporarily switching back to just windows
📈 26.92 Punkte
🐧 Linux Tipps
🍏 Using Smart Speakers While Temporarily Blind
📈 24.03 Punkte
🍏 iOS / Mac OS
🔧 DAY4-GIT BRANCH,STASH.
📈 23.59 Punkte
🔧 Programmierung
🔧 Git Stash - A Quick Primer
📈 23.59 Punkte
🔧 Programmierung