Skip to content

Instantly share code, notes, and snippets.

@Gonzalo2683
Forked from tonylukasavage/script.sh
Last active May 15, 2020 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gonzalo2683/526e2acb7ef0517d0faf88460a35e963 to your computer and use it in GitHub Desktop.
Save Gonzalo2683/526e2acb7ef0517d0faf88460a35e963 to your computer and use it in GitHub Desktop.
[Git stash] Move all uncommitted changes to a new branch and revert the existing branch to HEAD."master" has uncommitted changes. You decided you'd rather make those changes in "dev_branch". Here's how to move those uncommitted changes to "dev_branch" and then revert "master" to its last commit. #Git
# get into the master branch
git checkout master
# create a new branch for the changes and check it out
git checkout -b dev_branch
# stash the changes until we revert master
git stash
# go back to master
git checkout master
# reset to the last commit
git reset --hard HEAD
# go back to dev_branch
git checkout dev_branch
# re-apply the stashed changes and you are good to go
git stash apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment