Context: I\'m working on master adding a simple feature. After a few minutes I realize it was not so simple and it should have been better to work into a new branch.
If you want your current uncommited changes on the current branch to move to a new branch, use the following command to create a new branch and copy the uncommitted changes automatically.
git checkout -b branch_name
This will create a new branch from your current branch (assuming it to be master), copy the uncommited changes and switch to the new branch.
Commit your changes to the new branch.
git commit -m "First commit"
Since, a new branch is created, before pushing it to remote, you need to set the upstream. Use the below command to set the upstream and push it to remote.
git push --set-upstream origin feature/feature/NEWBRANCH
Once you hit this command, a new branch will be created at the remote and your new local branch will be pushed to remote.
Now, if you want to throw away your uncommited changes from master branch, use:
git checkout master -f
This will throw away any uncommitted local changes on checkout.