Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forgot to create new branch. How to transfer changes to new branch

Tags:

this happens to every developer time-to-time. You start coding a new feature and forget to branch first locally.

So if that happens is there a way I can say hey, transfer these uncommitted (or committed - yea I know those are both two scenarios which I'd like to cover with this) to a new branch for me locally so I don't have to back them out and copy my changes to a new branch to be able to carry on my way?

like image 924
PositiveGuy Avatar asked Jun 23 '17 19:06

PositiveGuy


People also ask

What happens if you make a change on a branch you don't own?

When you change a file in your work-tree, nothing happens to the copy in the index. It still matches the copy in the commit you chose. You have to run git add to copy the file from the work-tree, to the index.

How do you move uncommitted changes to a new branch?

Using the git checkout Command The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch.


1 Answers

If you haven't commited your changes yet, you can switch to a new branch prior to committing.

git checkout -b my-new-branch

This will create a new branch called my-new-branch and immediately check it out.

like image 152
mason Avatar answered Sep 18 '22 08:09

mason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!