+2 votes
1 view
in Devops and Agile by (22k points)
edited by

I started working on my master branch thinking that my task would be easy. After a while, I realized it would take more work and I want to do all this work in a new branch.

How can I create a new branch and take all these changes with me without dirtying master?

1 Answer

+3 votes
by (37.6k points)

As stated in https://intellipaat.com/community/10327/git-create-a-branch-from-unstaged-uncommitted-changes-on-master?show=10327#q10327 stash is not necessary.

To resolve this issue use:

git checkout -b topic/newbranch

Any uncommitted work will be taken along to the new branch.

If you try to push this to the repo then you will get a message and it shows how to resolve the issue.

fatal: The current branch feature/NEWBRANCH has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin feature/feature/NEWBRANCH

Then follow the same then you can push the git branch with current changes.

by (22k points)
Thanks. It was helpful.