git move changes to new branch code example
Example 1: how to move unstaged changes to different branch
git stash
git checkout -b new-branch
git stash pop
Example 2: how to move unstaged changes to different branch
git stash
git checkout correct-branch
git stash pop
Example 3: git bring your changes to a new branch
git checkout -b <new-branch>
// This will leave your current branch as it is, create and checkout a new branch and keep all your changes. You can then stage changes in files to commit with:
git add <files>
//and commit to your new branch with:
git commit -m "<Brief description of this commit>"
Example 4: how to move master changes to branch
git checkout -b newfeat master
git rebase --onto working-branch origin/master newfeat
git checkout master
git reset --hard origin/master
At this point you have:
*master pointing to the last pushed commit (origin/master)
*working-branch never changed
*a new newfeat branch that contains all the new commits and is ahead of working-branch.