Git create new branch from current - create git branch with current changes

1.2K    Asked by BenjaminMoore in Devops , Asked on Apr 20, 2021

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 from current and take all these changes with me without dirtying master?

Answered by Benjamin Moore

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 git create new branch from current changes


Your Answer

Interviews

Parent Categories