Complete Guide to Git Stash
How Git Stash Saved Me During a Build Error Crisis
As an intern, every day is a new learning experience. Yesterday, I faced a real challenge during server deployment. The project build failed with 7 errors, and the team needed a quick fix so deployment could continue.
At the same time, I had already made new changes in my branch. Some files were tracked, and some were untracked. I could not commit them because they were incomplete. But I also needed to switch focus immediately to fix the build issue and push clean code to the main branch.
That is when I used Git Stash — and it saved my time.
This blog explains what Git Stash is, why it is important, and how I used it in a real situation.
What is Git Stash?
Git Stash is a command that temporarily saves your current changes (tracked and untracked files) without committing them.
It allows you to:
-
Save incomplete work
-
Switch branches safely
-
Fix urgent issues
-
Restore your work later
In simple words:
👉 Git Stash = Temporary storage for your unfinished code.
The Real Problem I Faced
Here was my situation:
-
Deployment team reported 7 build errors
-
I had new local changes in my branch
-
Some files were tracked
-
Some files were untracked
-
I needed to quickly fix build errors
-
After fixing, I had to merge code to main for deployment
If I switched branches directly, Git would not allow it because of local changes.
I needed a clean working directory.
The Solution: Using Git Stash
Step 1: Check Current Status
git status
This shows modified, staged, and untracked files.
Step 2: Stash All Changes with Comment
git stash push -u -m "WIP before fixing build errors"
Explanation:
-
push→ Save changes -
-u→ Include untracked files -
-m→ Add a message for identification
After this:
✔ My working directory became clean
✔ I could switch branches safely
Step 3: Fix Build Errors
Now I switched to the required branch:
git checkout main
Pulled latest code:
git pull origin main
Solved the 7 build errors based on team suggestions.
Then committed:
git add .
git commit -m "Fixed build errors"
git push origin main
Now the team could deploy successfully.
Deployment Success
After pushing the fixed code:
-
Build ran successfully
-
No more errors
-
Deployment completed
-
Project went live
It was a relief moment.
But my previous changes were still safe in stash.
Step 4: Restore Stashed Changes
To see stash list:
git stash list
To restore:
git stash pop
This brought back all my previous local changes.
If you want to keep stash and apply:
git stash apply
In my case, I used pop because I wanted to remove it from stash after restoring.
Why Git Stash is Important for Freshers
As an intern, I learned something very important:
Real-world development is not just writing code.
It is about managing code safely.
Git Stash helps when:
-
You are working on a feature
-
Suddenly a bug appears in production
-
Build fails
-
You need to switch branches urgently
-
You don’t want to lose your work
Without Git Stash:
-
You might lose changes
-
You might create unnecessary commits
-
You may create merge conflicts
Standard Safe Workflow I Follow
Now I follow this process to avoid conflicts:
-
git status→ Always check current state -
git add <specific files>→ Add only required files -
git commit -m "clear message"→ Meaningful commit -
git pull origin branch-name→ Sync before push -
git push origin branch-name→ Push safely
If urgent issue comes:
👉 Use Git Stash
What I Learned from This Experience
-
Never panic during build errors
-
Keep working directory clean
-
Use stash instead of random commits
-
Always write proper stash messages
-
Understand Git deeply as a developer
Till now, by following proper Git workflow, I have not faced any major conflicts.
Final Thoughts
Git is not just a tool — it is a survival skill for developers.
Learning Git Stash gave me confidence in handling real deployment issues. As a fresher or intern, understanding Git deeply will make you more professional and reliable in your team.
If you are learning development, start practicing:
-
Branching
-
Pulling
-
Merging
-
Stashing
-
Resolving conflicts
Because real growth happens when you solve real problems.
If this story helped or motivated you, feel free to visit my profile Linkedin.com and connect.
Everyone starts somewhere — this was my start.
Comments
Post a Comment