Skip to main content

Command Palette

Search for a command to run...

Moving a Commit to a New Branch without Losing Progress! 💻🔧

Updated
1 min read
M

Hеllo, I'm Mohamеd Zhioua, a dеdicatеd Full-Stack JavaScript Dеvеlopеr basеd in Tunis, Tunisia 📍. I'm on a mission to shapе thе futurе through codе.

Sometimes we realize after committing that the changes belong on a different branch. Instead of manually copying files, here's a clean, simple way to "move" your last commit to a new branch! 👇

1️⃣ Reset the Last Commit (Keep Changes Staged)

git reset --soft HEAD~1

This removes your last commit but keeps the changes in your staging area.

2️⃣ Stash the Changes

git stash

Temporarily save the changes so you can apply them later.

3️⃣ Create or Switch to a New Branch

 git checkout -b new-branch-name

4️⃣ Reapply the Stashed Changes

git stash pop

Your changes are back and ready to be committed on the new branch.

💡 It's a great trick for keeping your branches clean and making sure commits are organized. No lost work, and no confusion! 🎉

#DevTips #GitTips #SoftwareDevelopment #CleanCode #VersionControl #FrontendEngineering #BackendEngineering

Mastering Git Commands

Part 1 of 1

A series on key Git commands and techniques. Learn how to streamline your workflow with practical examples, tips, and best practices. Perfect for both beginners and seasoned developers to elevate their version control skills.

More from this blog

U

Untitled Publication

27 posts

Hello, I'm Mohamed Zhioua. A passionate Full-Stack JavaScript Developer and blog writer.