Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a new git branch from the changes I have in the working tree?

Tags:

git

branch

I have edits to my working tree which I would like to continue working on in a branch. Will git checkout -b new_branch wipe out my current changes to the working tree? If so, how do I create a new branch and switch to it without reverting my working tree?

like image 859
Andrey Fedorov Avatar asked May 26 '09 08:05

Andrey Fedorov


2 Answers

Just do git checkout -b new_branch. It will create the new branch with the changes in your working tree untouched.

like image 128
1800 INFORMATION Avatar answered Sep 26 '22 03:09

1800 INFORMATION


If in the future you need to see whether Git would destroy something you haven’t committed yet (which it generally will never do), use git stash to stow away your changes. It will not save files that Git does not know about but Git will also refuse to overwrite unknown files in case of checkouts and similar operations.

like image 43
Bombe Avatar answered Sep 25 '22 03:09

Bombe