Git Like a Pro: Stashes, Pull Requests, Hotfixes & More!
Welcome, fellow codemancers! �✨ Whether you're a Git newbie or a seasoned version control wizard, there's always something new to learn in the wild world of Git. Today, we're diving into some essential Git concepts that will make your workflow smoother than a perfectly merged branch.
Let’s break down:
✅ Git Pull Requests (PRs) – The art of collaboration
✅ Git Stash – Your code’s "save for later" feature
✅ Git gitkeep – The hack for empty folders
✅ Git Hotfix Strategies – Putting out fires like a pro
Buckle up—this is going to be fun! 🚀
1. Git Pull Requests (PRs): The Social Network of Code
Ever tried baking a cake with a team where everyone adds their own ingredients without checking? Chaos, right? That’s what coding without Pull Requests feels like.
What’s a PR?
A Pull Request is like raising your hand and saying:
"Hey team, I made some changes. Can we merge this into the main code?"
Why PRs Rock:
✔ Code Review – Get feedback before breaking things.
✔ Automated Checks – Run tests before merging.
✔ Documentation – Tracks why changes were made.
How to Create a PR (GitHub Example):
git checkout -b my-awesome-feature # Create a new branch
git add . && git commit -m "Added unicorn mode"
git push origin my-awesome-feature # Push to remote Then, go to GitHub/GitLab and click "Create Pull Request". Boom! 🎉
Pro Tip: Write clear PR descriptions. Future-you will thank past-you.
2. Git Stash: The "Save for Later" Magic Trick
Ever been in the middle of coding, and suddenly—
"Emergency! Fix the login page NOW!"
But your current code is a mess. Enter git stash—the ultimate "pause button" for your work.
How to Stash Like a Ninja:
git stash # Saves your changes
git stash -u # Also stashes untracked files
git stash pop # Brings them back later
git stash list # See all your stashes
git stash apply stash@{2} # Apply a specific stash Why Stash?
Switch branches without committing half-baked code.
Temporarily store experiments.
Avoid
git commit -m "WIP: I have no idea what I'm doing"😅
3. Git gitkeep: The Empty Folder Hack
Git ignores empty folders. But sometimes, you need that empty logs/ or uploads/ directory in your repo.
The Hack?
Add a hidden .gitkeep file inside:
mkdir empty_folder
touch empty_folder/.gitkeep
git add empty_folder/.gitkeep
git commit -m "Keep this folder, Git!" Why not .gitignore?
.gitignoretells Git what to ignore..gitkeepis just a dummy file to force Git to track the folder.
(Fun fact: The name .gitkeep is just a convention—Git doesn’t actually care what you call it!)
4. Git Hotfixes: Putting Out Fires Without Panic
🚨 Critical bug in production! 🚨
You need a hotfix—a quick patch to save the day.
Hotfix Strategies:
Option 1: Branch from Main (Simple & Safe)
git checkout main
git pull
git checkout -b hotfix/login-crash
# Fix the bug → Commit → Push → PR → Merge Option 2: Cherry-Pick (For Complex Cases)
git checkout hotfix/login-crash
git commit -m "Fixed login crash"
git checkout main
git cherry-pick <commit-hash> # Apply just this fix to main Golden Rules of Hotfixes:
🔥 Test before merging! (No "works on my machine" excuses.)
🔥 Keep it small – Only fix the critical issue.
🔥 Document it – Add comments so others understand the urgency.
Go Through this video to Master Git:
Final Thoughts: Git Like a Pro
PRs = Teamwork. Don’t merge blindly.
Stash = Save progress. Like a video game quicksave.
gitkeep = Folder placeholder. Because Git hates emptiness.
Hotfixes = Emergency patches. Fast, precise, and tested.
Now go forth and Git responsibly, my friends! 🚀

