-
-
Save RaghavendraP/cb431ab0f62a8eac01be2e5d576eaf59 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### with new branch | |
# 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 | |
#### sync existing branch with master | |
# verify you are in correct branch | |
git branch | |
# stash local changes | |
git stash | |
# get into master branch | |
git checkout master | |
# get latest code from master | |
git fetch -p origin | |
# merge local master branch code with remote master | |
git merge origin/master | |
# get into your dev_branch | |
git checkout dev_branch | |
# merge local master code to local dev_branch | |
git merge master | |
# push local dev_branch changes to remote branch | |
git push origin dev_branch | |
# get the stashed changes | |
git stash pop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment