Moving a Commit to a New Branch without Losing Progress! ๐ป๐ง
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 rese...
Open on HashnodeSometimes 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