Day 31: Git Stash | 100 Days of DevOps
Content:
Today I worked on restoring stashed changes in a Git repository and pushing them to the remote repository. The task involved identifying a specific stash entry, applying it, and then committing and pushing those changes.
🔹 What I Learned
- How to view stashed changes using
git stash list - Difference between
git stash applyandgit stash pop - How to restore a specific stash using its identifier
Steps I Followed
1. Connected to Storage Server
ssh natasha@ststor01
2. Switched to Root User
sudo su
3. Navigated to the Repository
cd /usr/src/kodekloudrepos/apps
4. Checked Available Stashes
git stash list
Observed multiple stash entries:
stash@{0}
stash@{1}
5. Applied the Required Stash
git stash apply stash@{1}
This restored the changes (a new file welcome.txt) and staged them automatically.
6. Verified Changes
git status
Confirmed that welcome.txt was ready to be committed.
7. Committed the Changes
git commit -m "Restored changes from stash@{1}"
8. Pushed Changes to Remote Repository
git push origin master
9. Verified Push
The push was successful and changes were reflected in the remote repository.
🔹 My Understanding
This task helped me understand how Git stash works as a temporary storage for uncommitted changes. I learned how to retrieve specific stashed work without disturbing others and properly integrate it back into the repository workflow.
🔹 What I Found Interesting
I found it interesting that Git allows multiple stashes and lets us restore any specific one using an identifier. It’s a very useful feature when working on multiple tasks simultaneously, as it helps keep work organized without committing incomplete changes.
📌 Full notes: GitHub link