Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in DevOps and Agile by (29.3k 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 (50.2k 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.

Also, if you wish to learn and understand the concept of git in detail, you can read the Git Tutorial as well as enroll for Git Training.

git create new branch from current - create git branch with current changes
Intellipaat-community
by (29.3k points)
Thanks. It was helpful.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...