-
-
Save tonylukasavage/5672490 to your computer and use it in GitHub Desktop.
# 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 |
In addition to the above, my final step is to stage and commit all changes on the new branch.
I don't know whether I am doing something wrong. But after "git stash apply" in the new branch, when I go back to my "base branch" which is master in my case, it brings all the changes back there. Any suggestion?
# get into the master branch
git checkout master
# create a new branch for the changes and check it out
git checkout -b dev_branch
At this point you have a new branch with you changes uncommitted.
master
is already at its HEAD
state. And you new branch as well.
If you commit you changes at this step. Your changes are attached to your new branch. master
stay unchanged.
What is the point doing the 4 last command?
# 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
... it does bring you back at step 2.
I don't know whether I am doing something wrong. But after "git stash apply" in the new branch, when I go back to my "base branch" which is master in my case, it brings all the changes back there. Any suggestion?
@jhshah0111 commit the change when you are in you new branch
Thankyou for saving my hours.
Thanks. I added dropping the stash on the end.
My whole bash function within .bashrc is like this: