Monday, November 6, 2017

Git–Commit changes to a new branch

Did it ever happend to you that you were changing some code in one branch until you realized that you actually wanted to commit on another (new) branch?

I was expecting that this was not easy to do, but in fact it’s rather easy.

Don’t stage your changes, instead just create a new branch using

git checkout -b another-branch

This will create and checkout “another-branch”.

Now you can stage your files using

git add .

and commit them using

git commit -m <message>

Remark: This works in Visual Studio as well

No comments: