will creating a git branch delete my local changes [duplicate]
Possible Duplicate:
Git - Create a branch with current changes
I have done a whole lot of work on my project which I realise should have been done on another branch. If I create a branch now, will my current changes need to be checked in, or will they be wiped wh开发者_开发技巧en the new branch is created? I'm rather new to GIT and am just trying to avoid making a newbie mistake.
If you create a new branch from the current HEAD using:
$ git checkout -b newbranchname
Then changes will NOT be overwritten.
In your case, bdonlan's answer applies, since creating a new branch doesn't touch the working directory.
In more general cases where it would, Git will warn you and abort if you attempt to switch branches with working directory changes still present. Either way it's good about not losing changes.
In those cases, to move uncommitted working directory changes to a new branch, first save it to the Git stash:
git stash save
Then create and checkout that branch:
git checkout -b new-branch-name
Then pop your working directory changes from the Git stash:
git stash pop
They will be moved to the new branch. But if you feel unsafe you can always take a backup of your local project directory first.
精彩评论