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