0

I have uncommitted local changes. I would like to create a new branch and move the changes there.

Is my understanding correct? I should do:

git diff > my_work.txt
git checkout -b new_branch_name
git push origin new_branch_name
git apply my_work.txt
user997112
  • 25,084
  • 34
  • 143
  • 278

2 Answers2

0

git stash makes this a little easier.

$ git stash
$ git stash branch new_branch_name

This will preserved both staged and unstaged changes before creating and checking out the new branch.

chepner
  • 389,128
  • 51
  • 403
  • 529
0

You can use git stash:

Stash your changes (included untracked files)

git stash push --include-untracked

Verify clean working directory with git status

git status

Checkout your branch

git checkout <MyFancyBranch>

Apply stashed changes to current branch

git stash pop